From 7b0759f8b3b7ab4276a8668642dbd4b9586fafdd Mon Sep 17 00:00:00 2001 From: Hubert Plociniczak Date: Wed, 16 Nov 2022 11:23:52 +0100 Subject: [PATCH] Don't add module's builtins to the scope of a builtin type (#3791) 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. --- CHANGELOG.md | 2 + .../Standard/Base/0.0.0-dev/src/Data/Any.enso | 2 +- .../0.0.0-dev/src/Data/Text/Extensions.enso | 1 + .../Base/0.0.0-dev/src/Data/Time/Date.enso | 50 ++++++- .../0.0.0-dev/src/Data/Time/Date_Time.enso | 40 +++++- .../0.0.0-dev/src/Data/Time/Duration.enso | 31 ++++- .../0.0.0-dev/src/Data/Time/Time_Of_Day.enso | 33 ++++- .../0.0.0-dev/src/Data/Time/Time_Zone.enso | 32 ++++- .../Base/0.0.0-dev/src/Data/Vector.enso | 11 +- .../Base/0.0.0-dev/src/Error/Common.enso | 2 + .../lib/Standard/Base/0.0.0-dev/src/Main.enso | 2 +- .../lib/Standard/Base/0.0.0-dev/src/Meta.enso | 28 ++-- .../Base/0.0.0-dev/src/Polyglot/Java.enso | 22 +-- .../src/Polyglot/Proxy_Polyglot_Array.enso | 28 ---- .../Base/0.0.0-dev/src/System/File.enso | 63 +-------- .../src/Internal/Vector_Builder.enso | 1 + .../test/instrument/BuiltinTypesTest.scala | 7 +- .../builtin/debug/DebugBreakpointNode.java | 6 +- .../builtin/debug/DebugEvalNode.java | 3 +- ... ModuleDoesNotExistToDisplayTextNode.java} | 8 +- ...nitializedStateErrorToDisplayTextNode.java | 2 +- .../immutable/FromArrayBuiltinVectorNode.java | 9 +- .../FromPolyglotArrayBuiltinVectorNode.java | 6 +- .../builtin/interop/generic/ExecuteNode.java | 4 +- .../interop/generic/GetArraySizeNode.java | 3 +- .../generic/GetExecutableNameNode.java | 3 +- .../interop/generic/GetMemberNode.java | 3 +- .../interop/generic/GetMembersNode.java | 3 +- .../generic/GetSourceLocationNode.java | 3 +- .../generic/HasSourceLocationNode.java | 3 +- .../interop/generic/InstantiateNode.java | 3 +- .../builtin/interop/generic/InvokeNode.java | 3 +- .../generic/IsLanguageInstalledNode.java | 3 +- .../interop/generic/ReadArrayElementNode.java | 3 +- .../interop/java/AddToClassPathNode.java | 9 +- .../builtin/interop/java/LookupClassNode.java | 10 +- .../expression/builtin/io/PrintErrNode.java | 3 +- .../expression/builtin/io/PrintlnNode.java | 6 +- .../expression/builtin/io/ReadlnNode.java | 6 +- .../meta/CreateUnresolvedSymbolNode.java | 3 +- .../builtin/meta/GetAtomConstructorNode.java | 3 +- .../builtin/meta/GetAtomFieldsNode.java | 3 +- .../meta/GetConstructorFieldNamesNode.java | 3 +- .../builtin/meta/GetConstructorNameNode.java | 3 +- .../builtin/meta/GetPolyglotLanguageNode.java | 3 +- .../meta/GetQualifiedTypeNameNode.java | 3 +- .../builtin/meta/GetSimpleTypeNameNode.java | 6 +- .../builtin/meta/GetSourceLocationNode.java | 3 +- .../meta/GetUnresolvedSymbolNameNode.java | 3 +- .../meta/GetUnresolvedSymbolScopeNode.java | 3 +- .../builtin/meta/IsAtomConstructorNode.java | 3 +- .../expression/builtin/meta/IsAtomNode.java | 6 +- .../expression/builtin/meta/IsErrorNode.java | 3 +- .../builtin/meta/IsPolyglotNode.java | 3 +- .../builtin/meta/IsSameObjectNode.java | 3 +- .../builtin/meta/IsUnresolvedSymbolNode.java | 3 +- .../builtin/meta/NewAtomInstanceNode.java | 3 +- .../expression/builtin/meta/TypeOfNode.java | 7 +- .../expression/builtin/mutable/CopyNode.java | 6 +- .../builtin/resource/BracketNode.java | 3 +- .../builtin/runtime/AllowInputInNode.java | 3 +- .../builtin/runtime/AllowOutputInNode.java | 3 +- .../expression/builtin/runtime/GCNode.java | 8 +- .../builtin/runtime/GetStackTraceNode.java | 3 +- .../builtin/runtime/NoInlineNode.java | 3 +- .../builtin/runtime/NoInlineWithArgNode.java | 3 +- .../builtin/state/GetStateNode.java | 3 +- .../builtin/state/PutStateNode.java | 6 +- .../builtin/state/RunStateNode.java | 3 +- .../expression/builtin/text/OptimizeNode.java | 3 +- .../thread/WithInterruptHandlerNode.java | 3 +- .../builtin/unsafe/SetAtomFieldNode.java | 3 +- .../org/enso/interpreter/runtime/Module.java | 5 +- .../runtime/builtin/BuiltinFunction.java | 23 ++++ .../interpreter/runtime/builtin/Builtins.java | 130 ++++++++++-------- .../enso/interpreter/runtime/data/Array.java | 6 +- .../interpreter/runtime/data/EnsoDate.java | 6 +- .../runtime/data/EnsoDateTime.java | 28 ++-- .../runtime/data/EnsoDuration.java | 7 +- .../interpreter/runtime/data/EnsoFile.java | 11 +- .../runtime/data/EnsoTimeOfDay.java | 12 +- .../runtime/data/EnsoTimeZone.java | 14 +- .../enso/interpreter/runtime/data/Ref.java | 2 +- .../enso/interpreter/runtime/data/Vector.java | 5 +- .../interpreter/runtime/error/Warning.java | 21 ++- .../interpreter/runtime/system/System.java | 14 +- .../enso/compiler/codegen/IrToTruffle.scala | 10 +- .../test/semantic/PolyglotTest.scala | 7 +- .../org/enso/interpreter/dsl/Builtin.java | 7 + .../enso/interpreter/dsl/BuiltinMethod.java | 3 + .../dsl/BuiltinsMetadataProcessor.java | 2 +- .../interpreter/dsl/BuiltinsProcessor.java | 9 +- .../enso/interpreter/dsl/MethodProcessor.java | 25 ++-- .../builtins/MethodNodeClassGenerator.java | 12 +- .../dsl/model/MethodDefinition.java | 25 +++- test/Tests/src/Data/Array_Spec.enso | 3 +- test/Tests/src/Data/Time/Date_Spec.enso | 2 +- test/Tests/src/Semantic/Case_Spec.enso | 6 +- test/Tests/src/Semantic/Meta_Spec.enso | 2 +- .../Standard/Base/0.0.0-dev/src/Data/Any.enso | 3 + .../Base/0.0.0-dev/src/Data/Array.enso | 2 + .../Base/0.0.0-dev/src/Data/Boolean.enso | 3 + .../Base/0.0.0-dev/src/Data/Text.enso | 1 + .../0.0.0-dev/src/Data/Time/Time_Zone.enso | 4 +- .../lib/Standard/Base/0.0.0-dev/src/Main.enso | 4 +- .../Standard/Base/0.0.0-dev/src/Polyglot.enso | 1 + 106 files changed, 633 insertions(+), 359 deletions(-) delete mode 100644 distribution/lib/Standard/Base/0.0.0-dev/src/Polyglot/Proxy_Polyglot_Array.enso rename engine/runtime/src/main/java/org/enso/interpreter/node/expression/builtin/error/displaytext/{ModuleDoesNotExistErrorToDisplayTextNode.java => ModuleDoesNotExistToDisplayTextNode.java} (77%) create mode 100644 engine/runtime/src/main/java/org/enso/interpreter/runtime/builtin/BuiltinFunction.java diff --git a/CHANGELOG.md b/CHANGELOG.md index e5084d2f00..b269547326 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -431,6 +431,7 @@ - [Distinguish static and instance methods][3740] - [By-type pattern matching][3742] - [Fix performance of method calls on polyglot arrays][3781] +- [Improved support for static and non-static builtins][3791] - [Missing foreign language generates proper Enso error][3798] - [Made Vector performance to be on par with Array][3811] - [Introduced IO Permission Contexts][3828] @@ -494,6 +495,7 @@ [3764]: https://github.com/enso-org/enso/pull/3764 [3742]: https://github.com/enso-org/enso/pull/3742 [3781]: https://github.com/enso-org/enso/pull/3781 +[3791]: https://github.com/enso-org/enso/pull/3791 [3798]: https://github.com/enso-org/enso/pull/3798 [3811]: https://github.com/enso-org/enso/pull/3811 [3828]: https://github.com/enso-org/enso/pull/3828 diff --git a/distribution/lib/Standard/Base/0.0.0-dev/src/Data/Any.enso b/distribution/lib/Standard/Base/0.0.0-dev/src/Data/Any.enso index 5d0f4ce387..b1e7ee80eb 100644 --- a/distribution/lib/Standard/Base/0.0.0-dev/src/Data/Any.enso +++ b/distribution/lib/Standard/Base/0.0.0-dev/src/Data/Any.enso @@ -17,7 +17,7 @@ type Any Arguments: - handler: The function to call on this if it is an error value. catch_primitive : (Error -> Any) -> Any - catch_primitive handler = @Builtin_Method "Any.catch_primitive" + catch_primitive self handler = @Builtin_Method "Any.catch_primitive" ## Generic conversion of an arbitrary Enso value to a corresponding textual representation. diff --git a/distribution/lib/Standard/Base/0.0.0-dev/src/Data/Text/Extensions.enso b/distribution/lib/Standard/Base/0.0.0-dev/src/Data/Text/Extensions.enso index 01f8d858b5..54394bc05e 100644 --- a/distribution/lib/Standard/Base/0.0.0-dev/src/Data/Text/Extensions.enso +++ b/distribution/lib/Standard/Base/0.0.0-dev/src/Data/Text/Extensions.enso @@ -2,6 +2,7 @@ from Standard.Base import all +import Standard.Base.Data.Array import Standard.Base.Data.Text.Regex import Standard.Base.Data.Text.Matching_Mode diff --git a/distribution/lib/Standard/Base/0.0.0-dev/src/Data/Time/Date.enso b/distribution/lib/Standard/Base/0.0.0-dev/src/Data/Time/Date.enso index b0e5f50b3a..58eb720e29 100644 --- a/distribution/lib/Standard/Base/0.0.0-dev/src/Data/Time/Date.enso +++ b/distribution/lib/Standard/Base/0.0.0-dev/src/Data/Time/Date.enso @@ -36,6 +36,7 @@ today = now ## Constructs a new Date from a year, month, and day. Arguments + - year: The year to represent. - month: The month-of-year to represent, from 1 (January) to 12 (December). - day: The day-of-month to represent, from 1 to 31. It must be valid for the year and month. @@ -63,10 +64,23 @@ new year (month = 1) (day = 1) = instead of Enso format. Hopefully this will be fixed with https://github.com/enso-org/enso/pull/3559 Then this should be switched to use `Panic.catch_java`. - Panic.recover Any (Date.internal_new year month day) . catch Any e-> case e of + Panic.recover Any (new_builtin year month day) . catch Any e-> case e of Polyglot_Error_Data err -> Error.throw (Time_Error_Data err.getMessage) ex -> ex +## PRIVATE + Constructs a new Date from a year, month, and day. + + Arguments + - year: The year to represent. + - month: The month-of-year to represent, from 1 (January) to 12 (December). + - day: The day-of-month to represent, from 1 to 31. It must be valid for the + year and month. + + Recommended to use `Date.new` instead which handles potential exceptions. +new_builtin : Integer -> Integer -> Integer -> Date +new_builtin year month day = @Builtin_Method "Date.new_builtin" + ## ALIAS Date from Text Converts text containing a date into a Date object. @@ -132,13 +146,42 @@ new year (month = 1) (day = 1) = parse : Text -> (Text | Nothing) -> Date ! Time_Error parse text pattern=Nothing = result = Panic.recover Any <| case pattern of - Nothing -> Date.internal_parse text 0 - _ : Text -> Date.internal_parse text pattern + Nothing -> parse_builtin text 0 + _ : Text -> parse_builtin text pattern _ -> Panic.throw (Time_Error_Data "An invalid pattern was provided.") result . map_error <| case _ of Polyglot_Error_Data err -> Time_Error_Data err.getMessage ex -> ex +## PRIVATE + Converts text containing a date into a Date object. + + Arguments: + - text: The text to try and parse as a date. + - pattern: An optional pattern describing how to parse the text. + + Recommended to use `Date.parse` instead which handles potential exceptions. + + ? Pattern Syntax + Patterns are based on a simple sequence of letters and symbols. For + example, "d MMM yyyy" will format "2011-12-03" as "3 Dec 2011". + + ? Default Date Formatting + Unless you provide a custom format, the text must represent a valid date + that can be parsed using the ISO-8601 extended local date format. The + format consists of: + + - Four digits or more for the year. Years in the range 0000 to 9999 + will be pre-padded by zero to ensure four digits. Years outside + that range will have a prefixed positive or negative symbol. + - A dash + - Two digits for the month-of-year. This is pre-padded by zero to ensure + two digits. + - A dash + - Two digits for the day-of-month. This is pre-padded by zero to ensure two + digits. +parse_builtin : Text -> Any -> Date +parse_builtin text pattern = @Builtin_Method "Date.parse_builtin" ## This type represents a date, often viewed as year-month-day. @@ -484,7 +527,6 @@ type Date _ -> Error.throw (Illegal_Argument_Error_Data "Illegal period argument") - ## A Date to Json conversion. > Example diff --git a/distribution/lib/Standard/Base/0.0.0-dev/src/Data/Time/Date_Time.enso b/distribution/lib/Standard/Base/0.0.0-dev/src/Data/Time/Date_Time.enso index 519b7e8fa2..70f697cd73 100644 --- a/distribution/lib/Standard/Base/0.0.0-dev/src/Data/Time/Date_Time.enso +++ b/distribution/lib/Standard/Base/0.0.0-dev/src/Data/Time/Date_Time.enso @@ -86,9 +86,29 @@ now = @Builtin_Method "Date_Time.now" example_new = Date_Time.new 1986 8 5 new : Integer -> Integer -> Integer -> Integer -> Integer -> Integer -> Integer -> Time_Zone -> Date_Time ! Time_Error new year (month = 1) (day = 1) (hour = 0) (minute = 0) (second = 0) (nanosecond = 0) (zone = Time_Zone.system) = - Panic.catch_java Any (Date_Time.new_builtin year month day hour minute second nanosecond zone) java_exception-> + Panic.catch_java Any (new_builtin year month day hour minute second nanosecond zone) java_exception-> Error.throw (Time_Error_Data java_exception.getMessage) +## PRIVATE + + Obtains an instance of `Date_Time` from a year, month, day, hour, minute, + second, nanosecond and timezone. + + Arguments: + - year: The year to represent, any Integer is valid. + - month: the month-of-year to represent, from 1 (January) to 12 (December) + - day: the day-of-month to represent, from 1 to 31 and must be valid for the + year and month + - hour: the hour-of-day to represent, from 0 to 23 + - minute: the minute-of-hour to represent, from 0 to 59 + - second: the second-of-minute to represent, from 0 to 59 + - nanosecond: the nano-of-second to represent, from 0 to 999,999,999 + - zone: the timezone + + Recommended to use `Date_Time.new` instead which handles potential exceptions. +new_builtin : Integer -> Integer -> Integer -> Integer -> Integer -> Integer -> Integer -> Time_Zone -> Date_Time +new_builtin year month day hour minute second nanosecond zone = @Builtin_Method "Date_Time.new_builtin" + ## ALIAS Time from Text Obtains an instance of `Time` from a text such as @@ -171,9 +191,21 @@ parse : Text -> Text | Nothing -> Locale -> Date_Time ! Time_Error parse text pattern=Nothing locale=Locale.default = Panic.catch_java Any handler=(java_exception -> Error.throw (Time_Error_Data java_exception.getMessage)) <| case pattern of - Nothing -> Date_Time.parse_builtin text + Nothing -> parse_builtin text _ : Text -> Time_Utils.parse_datetime_format text pattern locale.java_locale +## PRIVATE + + Obtains an instance of `Time` from a text such as + "2007-12-03T10:15:30+01:00 Europe/Paris". + + Arguments: + - text: The text representing the time to be parsed. + + Recommended to use `Date_Time.parse_builtin` instead which handles potential exceptions + and date time formats. +parse_builtin : Text -> Date_Time +parse_builtin text = @Builtin_Method "Date_Time.parse_builtin" ## PRIVATE @@ -330,7 +362,7 @@ type Date_Time example_time_of_day = Date_Time.now.time_of_day time_of_day : Time_Of_Day - time_of_day self = self.to_localtime_builtin + time_of_day self = @Builtin_Method "Date_Time.time_of_day" ## Returns the number of week of year this date falls into. @@ -420,7 +452,7 @@ type Date_Time example_date = Date_Time.now.date date : Date - date self = self.to_localdate_builtin + date self = @Builtin_Method "Date_Time.date" ## ALIAS Change Time Zone diff --git a/distribution/lib/Standard/Base/0.0.0-dev/src/Data/Time/Duration.enso b/distribution/lib/Standard/Base/0.0.0-dev/src/Data/Time/Duration.enso index 76fac31cfe..294a850861 100644 --- a/distribution/lib/Standard/Base/0.0.0-dev/src/Data/Time/Duration.enso +++ b/distribution/lib/Standard/Base/0.0.0-dev/src/Data/Time/Duration.enso @@ -24,7 +24,20 @@ polyglot java import java.lang.ArithmeticException example_between = Duration.between Date_Time.now (Date_Time.new 2010 10 20) between : Date_Time -> Date_Time -> Boolean -> Duration between start_inclusive end_exclusive timezone_aware=True = - Duration.between_builtin start_inclusive end_exclusive timezone_aware + between_builtin start_inclusive end_exclusive timezone_aware + +## PRIVATE + Create an interval representing the duration between two points in time. + + Arguments: + - start_inclusive: The start datetime of the duration, included. + - end_exclusive: The end datetime of the duration, excluded. + - timezone_aware: Whether the duration between two given times should be + aware of the timezone, that can be set for start or end times. + + Recommended to use `Duration.between` instead which provides defaults. +between_builtin : Date_Time -> Date_Time -> Boolean -> Duration +between_builtin start_inclusive end_exclusive timezone_aware = @Builtin_Method "Duration.between_builtin" ## Create a duration from time units. @@ -43,7 +56,21 @@ between start_inclusive end_exclusive timezone_aware=True = example_duration = Duration.new hours=2 new : Integer -> Integer -> Integer -> Integer -> Integer -> Integer -> Duration new hours=0 minutes=0 seconds=0 milliseconds=0 nanoseconds=0 = - Duration.new_builtin hours minutes seconds milliseconds nanoseconds + new_builtin hours minutes seconds milliseconds nanoseconds + +## PRIVATE + Create a duration from time units. + + Arguments: + - hours: hours + - minutes: minutes + - seconds: seconds + - milliseconds: milliseconds + - nanoseconds: nanoseconds + + Recommended to use `Duration.new` instead which provides defaults. +new_builtin : Integer -> Integer -> Integer -> Integer -> Integer -> Integer -> Duration +new_builtin hours minutes seconds milliseconds nanoseconds = @Builtin_Method "Duration.new_builtin" ## Create a Duration from hours. hours : Integer -> Duration diff --git a/distribution/lib/Standard/Base/0.0.0-dev/src/Data/Time/Time_Of_Day.enso b/distribution/lib/Standard/Base/0.0.0-dev/src/Data/Time/Time_Of_Day.enso index da1dd4f06e..4f3daafb62 100644 --- a/distribution/lib/Standard/Base/0.0.0-dev/src/Data/Time/Time_Of_Day.enso +++ b/distribution/lib/Standard/Base/0.0.0-dev/src/Data/Time/Time_Of_Day.enso @@ -47,9 +47,24 @@ now = @Builtin_Method "Time_Of_Day.now" example_epoch = Time_Of_Day.new hour=9 minute=30 new : Integer -> Integer -> Integer -> Integer -> Time_Of_Day ! Time_Error new (hour = 0) (minute = 0) (second = 0) (nanosecond = 0) = - Panic.catch_java Any (Time_Of_Day.new_builtin hour minute second nanosecond) java_exception-> + Panic.catch_java Any (new_builtin hour minute second nanosecond) java_exception-> Error.throw (Time_Error_Data java_exception.getMessage) +## PRIVATE + + Obtains an instance of `Time_Of_Day` from an hour, minute, second + and nanosecond. + + Arguments: + - hour: The hour-of-day to represent, from 0 to 23. + - minute: The minute-of-hour to represent, from 0 to 59. + - second: The second-of-minute to represent, from 0 to 59. + - nanosecond: The nano-of-second to represent, from 0 to 999,999,999. + + Recommended to use `Time_Of_Day.new` instead which handles potential exceptions. +new_builtin : Integer -> Integer -> Integer -> Integer -> Time_Of_Day +new_builtin hour minute second nanosecond = @Builtin_Method "Time_Of_Day.new_builtin" + ## Obtains an instance of `Time_Of_Day` from a text such as "10:15". Arguments: @@ -115,9 +130,21 @@ parse : Text -> Text | Nothing -> Locale -> Time_Of_Day ! Time_Error parse text pattern=Nothing locale=Locale.default = Panic.catch_java Any handler=(java_exception -> Error.throw (Time_Error_Data java_exception.getMessage)) <| case pattern of - Nothing -> Time_Of_Day.parse_builtin text + Nothing -> parse_builtin text _ : Text -> Time_Utils.parse_time text pattern locale.java_locale +## PRIVATE + + Obtains an instance of `Time_Of_Day` from a text such as "10:15". + + Arguments: + - text: The text to parse as a time of day. + + Recommended to use `Time_Of_Day.parse_builtin` instead which handles potential + exceptions and different time formats. +parse_builtin : Text -> Time_Of_Day +parse_builtin text = @Builtin_Method "Time_Of_Day.parse_builtin" + ## PRIVATE This type is a date-time object that represents a time, often viewed @@ -204,7 +231,7 @@ type Time_Of_Day example_to_time = Time_Of_Day.new 12 30 . to_time (Date.new 2020) to_date_time : Date -> Time_Zone -> Date_Time - to_date_time self date (zone=Time_Zone.system) = self.to_time_builtin date zone + to_date_time self date (zone=Time_Zone.system) = self.to_date_time_builtin date zone ## Add the specified amount of time to this instant to get a new instant. diff --git a/distribution/lib/Standard/Base/0.0.0-dev/src/Data/Time/Time_Zone.enso b/distribution/lib/Standard/Base/0.0.0-dev/src/Data/Time/Time_Zone.enso index e0ec484495..769c3d00aa 100644 --- a/distribution/lib/Standard/Base/0.0.0-dev/src/Data/Time/Time_Zone.enso +++ b/distribution/lib/Standard/Base/0.0.0-dev/src/Data/Time/Time_Zone.enso @@ -60,7 +60,22 @@ utc = parse "UTC" example_new = Zone.new 1 1 50 new : Integer -> Integer -> Integer -> Time_Zone new (hours = 0) (minutes = 0) (seconds = 0) = - Time_Zone.new_builtin hours minutes seconds + new_builtin hours minutes seconds + +## PRIVATE + Obtains an instance of `Time_Zone` using an offset in hours, minutes and seconds + from the UTC zone. + + Arguments: + - hours: The timezone offset in hours from UTC, from -18 to +18. + - minutes: The timezone offset in minutes from the nearest hour, from 0 to + ±59. The sign must match that of the hours argument. + - seconds: The timezone offset in seconds from the nearest minute, from 0 to + ±59. The sign must match that of the minutes argument. + + Recommended to use `Time_Zone.new` instead which provides defaults. +new_builtin : Integer -> Integer -> Integer -> Time_Zone +new_builtin hours minutes seconds = @Builtin_Method "Time_Zone.new_builtin" ## ALIAS Time Zone from Text @@ -96,10 +111,21 @@ new (hours = 0) (minutes = 0) (seconds = 0) = from Standard.Base import Time_Zone example_parse = Time_Zone.parse "+03:02:01" -parse : Text -> Time_Zone +parse : Text -> Time_Zone ! Time_Error parse text = Panic.catch_java Any handler=(java_exception -> Error.throw (Time_Error_Data java_exception.getMessage)) <| - Time_Zone.parse_builtin text + parse_builtin text + +## PRIVATE + + This method parses the ID producing a `Time_Zone`. + + Arguments: + - text: The text representing a zone identifier. + + Recommended to use `Time_Zone.parse` instead which handles potential exceptions. +parse_builtin : Text -> Time_Zone +parse_builtin text = @Builtin_Method "Time_Zone.parse_builtin" ## PRIVATE diff --git a/distribution/lib/Standard/Base/0.0.0-dev/src/Data/Vector.enso b/distribution/lib/Standard/Base/0.0.0-dev/src/Data/Vector.enso index c5f875411c..dd60f9ba69 100644 --- a/distribution/lib/Standard/Base/0.0.0-dev/src/Data/Vector.enso +++ b/distribution/lib/Standard/Base/0.0.0-dev/src/Data/Vector.enso @@ -1,4 +1,5 @@ from Standard.Base import all +import Standard.Base.Data.Array import Standard.Base.Data.Index_Sub_Range import Standard.Base.Random @@ -26,7 +27,7 @@ polyglot java import java.lang.ClassCastException Vector.new my_vec.length (ix -> my_vec.at ix) new : Number -> (Number -> Any) -> Vector Any -new length constructor = @Builtin_Method "Vector.new_builtin" +new length constructor = @Builtin_Method "Vector.new" ## ADVANCED @@ -453,7 +454,7 @@ type Vector a self.fold 0 i-> vec-> Array.copy vec.to_array 0 arr i vec.length i + vec.length - Vector.from_polyglot_array arr + from_polyglot_array arr ## Applies a function to each element of the vector, returning the vector of results. @@ -568,7 +569,7 @@ type Vector a _ : Vector -> eq_at i = self.at i == that.at i if self.length == that.length then 0.up_to self.length . all eq_at else False - _ : Array -> + _ : Array.Array -> eq_at i = self.at i == that.at i if self.length == that.length then 0.up_to self.length . all eq_at else False _ -> False @@ -589,7 +590,7 @@ type Vector a arr = Array.new (self_len + that.length) Array.copy self.to_array 0 arr 0 self_len Array.copy that.to_array 0 arr self_len that.length - Vector.from_polyglot_array arr + from_polyglot_array arr ## Add `element` to the beginning of `self` vector. @@ -867,7 +868,7 @@ type Vector a handle_incomparable_value <| new_vec_arr.sort compare - Vector.from_polyglot_array new_vec_arr + from_polyglot_array new_vec_arr ## UNSTABLE Keeps only unique elements within the Vector, removing any duplicates. diff --git a/distribution/lib/Standard/Base/0.0.0-dev/src/Error/Common.enso b/distribution/lib/Standard/Base/0.0.0-dev/src/Error/Common.enso index 8335db8e8b..9044375035 100644 --- a/distribution/lib/Standard/Base/0.0.0-dev/src/Error/Common.enso +++ b/distribution/lib/Standard/Base/0.0.0-dev/src/Error/Common.enso @@ -766,6 +766,8 @@ type Time_Error epoch_start : Time_Error epoch_start = Time_Error_Data "Epoch start underflow" + to_display_text : Text + to_display_text self = self.error_message ## TODO Dubious constructor export from project.Error.Common.Unsupported_File_Type import all diff --git a/distribution/lib/Standard/Base/0.0.0-dev/src/Main.enso b/distribution/lib/Standard/Base/0.0.0-dev/src/Main.enso index b44af84f59..46dad9d480 100644 --- a/distribution/lib/Standard/Base/0.0.0-dev/src/Main.enso +++ b/distribution/lib/Standard/Base/0.0.0-dev/src/Main.enso @@ -87,6 +87,7 @@ export project.Error.Problem_Behavior export project.IO export project.Math export project.Meta +export project.Polyglot export project.Polyglot.Java export project.Runtime export project.Runtime.State @@ -119,7 +120,6 @@ from project.Data.Text.Span export all from project.Error.Common export all from project.Function export all from project.Nothing export all -from project.Polyglot export all from project.Runtime.Extensions export all from project.System.File_Format export File_Format, Plain_Text_Format, Plain_Text, Bytes, Infer, Auto_Detect from project.Data.Index_Sub_Range export First, Last diff --git a/distribution/lib/Standard/Base/0.0.0-dev/src/Meta.enso b/distribution/lib/Standard/Base/0.0.0-dev/src/Meta.enso index 1b57d591a4..8d464561dd 100644 --- a/distribution/lib/Standard/Base/0.0.0-dev/src/Meta.enso +++ b/distribution/lib/Standard/Base/0.0.0-dev/src/Meta.enso @@ -330,8 +330,8 @@ is_a value typ = if is_same_object value typ then True else _ : Duration.Duration -> typ.is_same_object_as Duration.Duration _ : Time_Of_Day.Time_Of_Day -> typ.is_same_object_as Time_Of_Day.Time_Of_Day _ : Time_Zone.Time_Zone -> typ.is_same_object_as Time_Zone.Time_Zone - Base.Polyglot -> - typ==Base.Polyglot || java_instance_check value typ + Base.Polyglot.Polyglot -> + typ==Base.Polyglot.Polyglot || java_instance_check value typ _ -> meta_val = meta value case meta_val of @@ -361,7 +361,7 @@ java_instance_check value typ = Arguments: - value: the value to get the type of. type_of : Any -> Any -type_of value = @Builtin_Method "Meta.type_of_builtin" +type_of value = @Builtin_Method "Meta.type_of" # TODO Dubious constructor export from project.Meta.Language import all @@ -427,17 +427,6 @@ is_polyglot value = @Builtin_Method "Meta.is_polyglot" is_unresolved_symbol : Any -> Boolean is_unresolved_symbol value = @Builtin_Method "Meta.is_unresolved_symbol" -## PRIVATE - - Returns a Text representing the source location of a stack frame above - the call. - - Arguments: - - frames_to_skip: how many frames on the stack to skip. Called with 0 - will return exact location of the call. -get_source_location_builtin : Integer -> Text -get_source_location_builtin frames_to_skip = @Builtin_Method "Meta.get_source_location_builtin" - ## PRIVATE Returns a Text representing the source location of a stack frame above @@ -455,6 +444,17 @@ get_source_location : Integer -> Text get_source_location skip_frames = get_source_location_builtin skip_frames+1 +## PRIVATE + + Returns a Text representing the source location of a stack frame above + the call. + + Arguments: + - frames_to_skip: how many frames on the stack to skip. Called with 0 + will return exact location of the call. +get_source_location_builtin : Integer -> Text +get_source_location_builtin frames_to_skip = @Builtin_Method "Meta.get_source_location_builtin" + ## PRIVATE Displays the type of the provided value as text. diff --git a/distribution/lib/Standard/Base/0.0.0-dev/src/Polyglot/Java.enso b/distribution/lib/Standard/Base/0.0.0-dev/src/Polyglot/Java.enso index 9154420d51..7c55d8048f 100644 --- a/distribution/lib/Standard/Base/0.0.0-dev/src/Polyglot/Java.enso +++ b/distribution/lib/Standard/Base/0.0.0-dev/src/Polyglot/Java.enso @@ -1,19 +1,19 @@ ## Utilities for working with Java polyglot objects. -type Java - ## Adds the provided entry to the host class path. - Arguments: - - path: The java classpath entry to add. +## Adds the provided entry to the host class path. - Use of the actual polyglot imports system should be preferred to use of - this method. + Arguments: + - path: The java classpath entry to add. - > Example - Adding Random to the classpath. + Use of the actual polyglot imports system should be preferred to use of + this method. - Java.add_to_class_path "java.util.Random" - add_to_class_path : Text -> Nothing - add_to_class_path path = @Builtin_Method "Java.add_to_class_path" + > Example + Adding Random to the classpath. + + Java.add_to_class_path "java.util.Random" +add_to_class_path : Text -> Nothing +add_to_class_path path = @Builtin_Method "Java.add_to_class_path" ## Looks up a java symbol on the classpath by name. diff --git a/distribution/lib/Standard/Base/0.0.0-dev/src/Polyglot/Proxy_Polyglot_Array.enso b/distribution/lib/Standard/Base/0.0.0-dev/src/Polyglot/Proxy_Polyglot_Array.enso deleted file mode 100644 index a693902061..0000000000 --- a/distribution/lib/Standard/Base/0.0.0-dev/src/Polyglot/Proxy_Polyglot_Array.enso +++ /dev/null @@ -1,28 +0,0 @@ -from Standard.Base import Polyglot, Array - -## TODO Dubious constructor export -from project.Polyglot.Proxy_Polyglot_Array.Proxy_Polyglot_Array import all -from project.Polyglot.Proxy_Polyglot_Array.Proxy_Polyglot_Array export all - -## Advanced - - Wrapper for Polyglot Arrays -type Proxy_Polyglot_Array - - Proxy_Polyglot_Array_Data arr - - ## Returns the number of elements stored in this Polyglot Array. - - length : Number - length self = - Polyglot.get_array_size self.arr - - ## Gets an element from this Polyglot Array at a specified index (0-based). - - at : Number -> Any - at self index = - Polyglot.read_array_element self.arr index - - to_array : Array Any - to_array self = - self.arr diff --git a/distribution/lib/Standard/Base/0.0.0-dev/src/System/File.enso b/distribution/lib/Standard/Base/0.0.0-dev/src/System/File.enso index bd0a0e0781..4f1611b2d4 100644 --- a/distribution/lib/Standard/Base/0.0.0-dev/src/System/File.enso +++ b/distribution/lib/Standard/Base/0.0.0-dev/src/System/File.enso @@ -1,12 +1,13 @@ from Standard.Base import all -import Standard.Base.System.File.Option -import Standard.Base.System.File.File_Permissions +import Standard.Base.Data.Array import Standard.Base.Data.Text.Text_Sub_Range +from Standard.Base.Error.Common import Unsupported_File_Type from Standard.Base.Error.Problem_Behavior import Report_Warning import Standard.Base.Runtime.Resource from Standard.Base.Runtime.Resource import Managed_Resource -from Standard.Base.Error.Common import Unsupported_File_Type +import Standard.Base.System.File.Option +import Standard.Base.System.File.File_Permissions polyglot java import org.enso.base.Array_Builder polyglot java import org.enso.base.Encoding_Utils @@ -391,14 +392,6 @@ type File creation_time self = handle_java_exceptions self <| self.creation_time_builtin - ## PRIVATE - - Builtin method that gets this file's creation time. - Recommended to use `File.creation_time` instead which handles potential - exceptions. - creation_time_builtin : File -> ZonedDateTime - creation_time_builtin self = @Builtin_Method "File.creation_time_builtin" - ## Gets the last modified time of a file. > Example @@ -411,14 +404,6 @@ type File last_modified_time self = handle_java_exceptions self <| self.last_modified_time_builtin - ## PRIVATE - - Builtin method that gets this file's last modified time. - Recommended to use `File.last_modified_time` instead which handles - potential exceptions. - last_modified_time_builtin : ZonedDateTime - last_modified_time_builtin self = @Builtin_Method "File.last_modified_time_builtin" - ## Gets the POSIX permissions associated with the file. > Example @@ -431,15 +416,6 @@ type File posix_permissions self = File_Permissions.from_java_set self.posix_permissions_builtin - ## PRIVATE - - Builtin method that gets this file's POSIX permissions as a Java Set. - Recommended to use `File.posix_permissions` instead which handles - potential exceptions and converts an Enso representation of the - permissions. - posix_permissions_builtin : Set - posix_permissions_builtin self = @Builtin_Method "File.posix_permissions_builtin" - ## Checks whether the file exists and is a directory. > Example @@ -593,13 +569,6 @@ type File delete self = handle_java_exceptions self self.delete_builtin - ## PRIVATE - - Builtin method that deletes the file. - Recommended to use `File.delete` instead which handles potential exceptions. - delete_builtin : Nothing - delete_builtin self = @Builtin_Method "File.delete_builtin" - ## Moves the file to the specified destination. Arguments: @@ -614,13 +583,6 @@ type File self.copy_builtin destination copy_options False -> self.copy_builtin destination Array.empty - ## PRIVATE - - Builtin method that copies this file to a new destination. - Recommended to use `File.copy_to` instead which handles potential exceptions. - copy_builtin : File -> Array Any -> Nothing - copy_builtin self destination copy_options = @Builtin_Method "File.copy_builtin" - ## Moves the file to the specified destination. Arguments: @@ -635,13 +597,6 @@ type File self.move_builtin destination copy_options False -> self.move_builtin destination Array.empty - ## PRIVATE - - Builtin method that moves this file to a new destination. - Recommended to use `File.move_to` instead which handles potential exceptions. - move_builtin : File -> Array Any -> Nothing - move_builtin self destination copy_options = @Builtin_Method "File.move_builtin" - ## Deletes the file if it exists on disk. If the file is a directory, it must be empty, otherwise a `Panic` will @@ -700,10 +655,6 @@ type File handle_java_exceptions self <| Vector.from_polyglot_array (self.read_last_bytes_builtin n) - ## PRIVATE - read_last_bytes_builtin : Integer -> Array - read_last_bytes_builtin self n = @Builtin_Method "File.read_last_bytes_builtin" - ## Lists files contained in the directory denoted by this file. Arguments: @@ -790,12 +741,6 @@ type File list_immediate_children : Vector.Vector File list_immediate_children self = Vector.from_polyglot_array (self.list_immediate_children_array) - ## PRIVATE - - Utility function that lists immediate children of a directory. - list_immediate_children_array : Array File - list_immediate_children_array self = @Builtin_Method "File.list_immediate_children_array" - ## PRIVATE Return the absolute path of this File diff --git a/distribution/lib/Standard/Table/0.0.0-dev/src/Internal/Vector_Builder.enso b/distribution/lib/Standard/Table/0.0.0-dev/src/Internal/Vector_Builder.enso index 3e3622b0a2..844178e207 100644 --- a/distribution/lib/Standard/Table/0.0.0-dev/src/Internal/Vector_Builder.enso +++ b/distribution/lib/Standard/Table/0.0.0-dev/src/Internal/Vector_Builder.enso @@ -1,4 +1,5 @@ from Standard.Base import all +import Standard.Base.Data.Array from project.Internal.Vector_Builder.Vector_Builder import Leaf, Append diff --git a/engine/runtime-with-instruments/src/test/scala/org/enso/interpreter/test/instrument/BuiltinTypesTest.scala b/engine/runtime-with-instruments/src/test/scala/org/enso/interpreter/test/instrument/BuiltinTypesTest.scala index 785563408a..a25eb8e63d 100644 --- a/engine/runtime-with-instruments/src/test/scala/org/enso/interpreter/test/instrument/BuiltinTypesTest.scala +++ b/engine/runtime-with-instruments/src/test/scala/org/enso/interpreter/test/instrument/BuiltinTypesTest.scala @@ -344,10 +344,10 @@ class BuiltinTypesTest val requestId = UUID.randomUUID() val metadata = new Metadata - val idMain = metadata.addItem(37, 19) + val idMain = metadata.addItem(39, 19) val code = - """from Standard.Base import all + """import Standard.Base.Data.Array | |main = | Array.new_1 42 @@ -370,10 +370,11 @@ class BuiltinTypesTest val requestId = UUID.randomUUID() val metadata = new Metadata - val idMain = metadata.addItem(37, 34) + val idMain = metadata.addItem(69, 34) val code = """from Standard.Base import all + |import Standard.Base.Data.Array | |main = | Vector.from_array Array.empty diff --git a/engine/runtime/src/main/java/org/enso/interpreter/node/expression/builtin/debug/DebugBreakpointNode.java b/engine/runtime/src/main/java/org/enso/interpreter/node/expression/builtin/debug/DebugBreakpointNode.java index 9e4e378a77..c1850293f5 100644 --- a/engine/runtime/src/main/java/org/enso/interpreter/node/expression/builtin/debug/DebugBreakpointNode.java +++ b/engine/runtime/src/main/java/org/enso/interpreter/node/expression/builtin/debug/DebugBreakpointNode.java @@ -13,7 +13,11 @@ import org.enso.interpreter.runtime.Context; import org.enso.interpreter.runtime.callable.CallerInfo; import org.enso.interpreter.runtime.state.State; -@BuiltinMethod(type = "Debug", name = "breakpoint", description = "Instrumentation marker node.") +@BuiltinMethod( + type = "Debug", + name = "breakpoint", + description = "Instrumentation marker node.", + autoRegister = false) @GenerateWrapper public abstract class DebugBreakpointNode extends Node implements InstrumentableNode { /** diff --git a/engine/runtime/src/main/java/org/enso/interpreter/node/expression/builtin/debug/DebugEvalNode.java b/engine/runtime/src/main/java/org/enso/interpreter/node/expression/builtin/debug/DebugEvalNode.java index 1e4e750ce2..8437f4c18e 100644 --- a/engine/runtime/src/main/java/org/enso/interpreter/node/expression/builtin/debug/DebugEvalNode.java +++ b/engine/runtime/src/main/java/org/enso/interpreter/node/expression/builtin/debug/DebugEvalNode.java @@ -12,7 +12,8 @@ import org.enso.interpreter.runtime.state.State; @BuiltinMethod( type = "Debug", name = "eval", - description = "Evaluates an expression passed as a Text argument, in the caller frame.") + description = "Evaluates an expression passed as a Text argument, in the caller frame.", + autoRegister = false) public class DebugEvalNode extends Node { private @Child EvalNode evalNode = EvalNode.build(); private @Child ExpectTextNode expectTextNode = ExpectTextNode.build(); diff --git a/engine/runtime/src/main/java/org/enso/interpreter/node/expression/builtin/error/displaytext/ModuleDoesNotExistErrorToDisplayTextNode.java b/engine/runtime/src/main/java/org/enso/interpreter/node/expression/builtin/error/displaytext/ModuleDoesNotExistToDisplayTextNode.java similarity index 77% rename from engine/runtime/src/main/java/org/enso/interpreter/node/expression/builtin/error/displaytext/ModuleDoesNotExistErrorToDisplayTextNode.java rename to engine/runtime/src/main/java/org/enso/interpreter/node/expression/builtin/error/displaytext/ModuleDoesNotExistToDisplayTextNode.java index 1d96508807..b7d2005bb7 100644 --- a/engine/runtime/src/main/java/org/enso/interpreter/node/expression/builtin/error/displaytext/ModuleDoesNotExistErrorToDisplayTextNode.java +++ b/engine/runtime/src/main/java/org/enso/interpreter/node/expression/builtin/error/displaytext/ModuleDoesNotExistToDisplayTextNode.java @@ -9,10 +9,10 @@ import org.enso.interpreter.runtime.callable.atom.AtomConstructor; import org.enso.interpreter.runtime.data.text.Text; import org.enso.interpreter.runtime.type.TypesGen; -@BuiltinMethod(type = "Module_Does_Not_Exist_Error", name = "to_display_text") -public abstract class ModuleDoesNotExistErrorToDisplayTextNode extends Node { - static ModuleDoesNotExistErrorToDisplayTextNode build() { - return ModuleDoesNotExistErrorToDisplayTextNodeGen.create(); +@BuiltinMethod(type = "Module_Does_Not_Exist", name = "to_display_text") +public abstract class ModuleDoesNotExistToDisplayTextNode extends Node { + static ModuleDoesNotExistToDisplayTextNode build() { + return ModuleDoesNotExistToDisplayTextNodeGen.create(); } abstract Text execute(Object self); diff --git a/engine/runtime/src/main/java/org/enso/interpreter/node/expression/builtin/error/displaytext/UninitializedStateErrorToDisplayTextNode.java b/engine/runtime/src/main/java/org/enso/interpreter/node/expression/builtin/error/displaytext/UninitializedStateErrorToDisplayTextNode.java index 82e0286625..9f2c461577 100644 --- a/engine/runtime/src/main/java/org/enso/interpreter/node/expression/builtin/error/displaytext/UninitializedStateErrorToDisplayTextNode.java +++ b/engine/runtime/src/main/java/org/enso/interpreter/node/expression/builtin/error/displaytext/UninitializedStateErrorToDisplayTextNode.java @@ -9,7 +9,7 @@ import org.enso.interpreter.runtime.callable.atom.Atom; import org.enso.interpreter.runtime.callable.atom.AtomConstructor; import org.enso.interpreter.runtime.data.text.Text; -@BuiltinMethod(type = "Uninitialized_State_Error", name = "to_display_text") +@BuiltinMethod(type = "Uninitialized_State", name = "to_display_text") public abstract class UninitializedStateErrorToDisplayTextNode extends Node { static UninitializedStateErrorToDisplayTextNode build() { return UninitializedStateErrorToDisplayTextNodeGen.create(); diff --git a/engine/runtime/src/main/java/org/enso/interpreter/node/expression/builtin/immutable/FromArrayBuiltinVectorNode.java b/engine/runtime/src/main/java/org/enso/interpreter/node/expression/builtin/immutable/FromArrayBuiltinVectorNode.java index 6c56567b77..728708096b 100644 --- a/engine/runtime/src/main/java/org/enso/interpreter/node/expression/builtin/immutable/FromArrayBuiltinVectorNode.java +++ b/engine/runtime/src/main/java/org/enso/interpreter/node/expression/builtin/immutable/FromArrayBuiltinVectorNode.java @@ -2,14 +2,10 @@ package org.enso.interpreter.node.expression.builtin.immutable; import com.oracle.truffle.api.dsl.*; import com.oracle.truffle.api.interop.InteropLibrary; -import com.oracle.truffle.api.interop.InvalidArrayIndexException; -import com.oracle.truffle.api.interop.UnsupportedMessageException; import com.oracle.truffle.api.library.CachedLibrary; import com.oracle.truffle.api.nodes.Node; -import org.enso.interpreter.dsl.*; -import org.enso.interpreter.epb.node.CoercePrimitiveNode; +import org.enso.interpreter.dsl.BuiltinMethod; import org.enso.interpreter.node.expression.builtin.mutable.CoerceArrayNode; -import org.enso.interpreter.node.expression.foreign.CoerceNothing; import org.enso.interpreter.runtime.Context; import org.enso.interpreter.runtime.data.Array; import org.enso.interpreter.runtime.error.PanicException; @@ -18,7 +14,8 @@ import org.enso.interpreter.runtime.data.Vector; @BuiltinMethod( type = "Vector", name = "from_array", - description = "Creates a Vector by copying Array content.") + description = "Creates a Vector by copying Array content.", + autoRegister = false) public abstract class FromArrayBuiltinVectorNode extends Node { static FromArrayBuiltinVectorNode build() { return FromArrayBuiltinVectorNodeGen.create(); diff --git a/engine/runtime/src/main/java/org/enso/interpreter/node/expression/builtin/immutable/FromPolyglotArrayBuiltinVectorNode.java b/engine/runtime/src/main/java/org/enso/interpreter/node/expression/builtin/immutable/FromPolyglotArrayBuiltinVectorNode.java index 94a0e1c141..3cb4153c2d 100644 --- a/engine/runtime/src/main/java/org/enso/interpreter/node/expression/builtin/immutable/FromPolyglotArrayBuiltinVectorNode.java +++ b/engine/runtime/src/main/java/org/enso/interpreter/node/expression/builtin/immutable/FromPolyglotArrayBuiltinVectorNode.java @@ -4,7 +4,7 @@ import com.oracle.truffle.api.dsl.*; import com.oracle.truffle.api.interop.InteropLibrary; import com.oracle.truffle.api.library.CachedLibrary; import com.oracle.truffle.api.nodes.Node; -import org.enso.interpreter.dsl.*; +import org.enso.interpreter.dsl.BuiltinMethod; import org.enso.interpreter.runtime.Context; import org.enso.interpreter.runtime.error.PanicException; import org.enso.interpreter.runtime.data.Vector; @@ -12,7 +12,9 @@ import org.enso.interpreter.runtime.data.Vector; @BuiltinMethod( type = "Vector", name = "from_polyglot_array", - description = "Returns an Array representation of this Vector.") + description = + "Creates a Vector by providing its underlying storage as a polyglot array. The underlying array should be guaranteed to never be mutated.", + autoRegister = false) public abstract class FromPolyglotArrayBuiltinVectorNode extends Node { static FromPolyglotArrayBuiltinVectorNode build() { diff --git a/engine/runtime/src/main/java/org/enso/interpreter/node/expression/builtin/interop/generic/ExecuteNode.java b/engine/runtime/src/main/java/org/enso/interpreter/node/expression/builtin/interop/generic/ExecuteNode.java index 2aadc27053..a0c4285de7 100644 --- a/engine/runtime/src/main/java/org/enso/interpreter/node/expression/builtin/interop/generic/ExecuteNode.java +++ b/engine/runtime/src/main/java/org/enso/interpreter/node/expression/builtin/interop/generic/ExecuteNode.java @@ -12,13 +12,13 @@ import org.enso.interpreter.Constants; import org.enso.interpreter.dsl.BuiltinMethod; import org.enso.interpreter.node.expression.builtin.interop.syntax.HostValueToEnsoNode; import org.enso.interpreter.node.expression.builtin.mutable.CoerceArrayNode; -import org.enso.interpreter.runtime.data.Array; import org.enso.interpreter.runtime.error.PanicException; @BuiltinMethod( type = "Polyglot", name = "execute", - description = "Executes a polyglot function object (e.g. a lambda).") + description = "Executes a polyglot function object (e.g. a lambda).", + autoRegister = false) public abstract class ExecuteNode extends Node { private @Child InteropLibrary library = InteropLibrary.getFactory().createDispatched(Constants.CacheSizes.BUILTIN_INTEROP_DISPATCH); diff --git a/engine/runtime/src/main/java/org/enso/interpreter/node/expression/builtin/interop/generic/GetArraySizeNode.java b/engine/runtime/src/main/java/org/enso/interpreter/node/expression/builtin/interop/generic/GetArraySizeNode.java index 57a07578f2..2aae9ccc7d 100644 --- a/engine/runtime/src/main/java/org/enso/interpreter/node/expression/builtin/interop/generic/GetArraySizeNode.java +++ b/engine/runtime/src/main/java/org/enso/interpreter/node/expression/builtin/interop/generic/GetArraySizeNode.java @@ -13,7 +13,8 @@ import org.enso.interpreter.runtime.error.PanicException; @BuiltinMethod( type = "Polyglot", name = "get_array_size", - description = "Returns the size of a polyglot array.") + description = "Returns the size of a polyglot array.", + autoRegister = false) public class GetArraySizeNode extends Node { private @Child InteropLibrary library = InteropLibrary.getFactory().createDispatched(Constants.CacheSizes.BUILTIN_INTEROP_DISPATCH); diff --git a/engine/runtime/src/main/java/org/enso/interpreter/node/expression/builtin/interop/generic/GetExecutableNameNode.java b/engine/runtime/src/main/java/org/enso/interpreter/node/expression/builtin/interop/generic/GetExecutableNameNode.java index b8071ad910..28578d3b50 100644 --- a/engine/runtime/src/main/java/org/enso/interpreter/node/expression/builtin/interop/generic/GetExecutableNameNode.java +++ b/engine/runtime/src/main/java/org/enso/interpreter/node/expression/builtin/interop/generic/GetExecutableNameNode.java @@ -14,7 +14,8 @@ import org.enso.interpreter.runtime.error.PanicException; @BuiltinMethod( type = "Polyglot", name = "get_executable_name", - description = "Returns the executable name of a polyglot object.") + description = "Returns the executable name of a polyglot object.", + autoRegister = false) public class GetExecutableNameNode extends Node { private @Child InteropLibrary functionsLibrary = InteropLibrary.getFactory().createDispatched(Constants.CacheSizes.BUILTIN_INTEROP_DISPATCH); diff --git a/engine/runtime/src/main/java/org/enso/interpreter/node/expression/builtin/interop/generic/GetMemberNode.java b/engine/runtime/src/main/java/org/enso/interpreter/node/expression/builtin/interop/generic/GetMemberNode.java index 98ab061743..faa7778b0b 100644 --- a/engine/runtime/src/main/java/org/enso/interpreter/node/expression/builtin/interop/generic/GetMemberNode.java +++ b/engine/runtime/src/main/java/org/enso/interpreter/node/expression/builtin/interop/generic/GetMemberNode.java @@ -13,7 +13,8 @@ import org.enso.interpreter.runtime.error.PanicException; @BuiltinMethod( type = "Polyglot", name = "get_member", - description = "Gets a member by name from a polyglot object.") + description = "Gets a member by name from a polyglot object.", + autoRegister = false) public class GetMemberNode extends Node { private @Child InteropLibrary library = InteropLibrary.getFactory().createDispatched(Constants.CacheSizes.BUILTIN_INTEROP_DISPATCH); diff --git a/engine/runtime/src/main/java/org/enso/interpreter/node/expression/builtin/interop/generic/GetMembersNode.java b/engine/runtime/src/main/java/org/enso/interpreter/node/expression/builtin/interop/generic/GetMembersNode.java index 20428265dc..c904913d20 100644 --- a/engine/runtime/src/main/java/org/enso/interpreter/node/expression/builtin/interop/generic/GetMembersNode.java +++ b/engine/runtime/src/main/java/org/enso/interpreter/node/expression/builtin/interop/generic/GetMembersNode.java @@ -10,7 +10,8 @@ import org.enso.interpreter.runtime.data.Array; @BuiltinMethod( type = "Polyglot", name = "get_members", - description = "Returns a polyglot array of the object's member names.") + description = "Returns a polyglot array of the object's member names.", + autoRegister = false) public class GetMembersNode extends Node { private @Child InteropLibrary library = InteropLibrary.getFactory().createDispatched(Constants.CacheSizes.BUILTIN_INTEROP_DISPATCH); diff --git a/engine/runtime/src/main/java/org/enso/interpreter/node/expression/builtin/interop/generic/GetSourceLocationNode.java b/engine/runtime/src/main/java/org/enso/interpreter/node/expression/builtin/interop/generic/GetSourceLocationNode.java index e623399fd7..47bb8ca0a3 100644 --- a/engine/runtime/src/main/java/org/enso/interpreter/node/expression/builtin/interop/generic/GetSourceLocationNode.java +++ b/engine/runtime/src/main/java/org/enso/interpreter/node/expression/builtin/interop/generic/GetSourceLocationNode.java @@ -14,7 +14,8 @@ import org.enso.interpreter.runtime.error.PanicException; @BuiltinMethod( type = "Polyglot", name = "get_source_location", - description = "Returns the source location of a polyglot object.") + description = "Returns the source location of a polyglot object.", + autoRegister = false) public class GetSourceLocationNode extends Node { private @Child InteropLibrary library = InteropLibrary.getFactory().createDispatched(Constants.CacheSizes.BUILTIN_INTEROP_DISPATCH); diff --git a/engine/runtime/src/main/java/org/enso/interpreter/node/expression/builtin/interop/generic/HasSourceLocationNode.java b/engine/runtime/src/main/java/org/enso/interpreter/node/expression/builtin/interop/generic/HasSourceLocationNode.java index 1c00b080f3..ae60b31d58 100644 --- a/engine/runtime/src/main/java/org/enso/interpreter/node/expression/builtin/interop/generic/HasSourceLocationNode.java +++ b/engine/runtime/src/main/java/org/enso/interpreter/node/expression/builtin/interop/generic/HasSourceLocationNode.java @@ -9,7 +9,8 @@ import org.enso.interpreter.dsl.BuiltinMethod; @BuiltinMethod( type = "Polyglot", name = "has_source_location", - description = "Checks if an object has a source location.") + description = "Checks if an object has a source location.", + autoRegister = false) public class HasSourceLocationNode extends Node { private @Child InteropLibrary library = InteropLibrary.getFactory().createDispatched(Constants.CacheSizes.BUILTIN_INTEROP_DISPATCH); diff --git a/engine/runtime/src/main/java/org/enso/interpreter/node/expression/builtin/interop/generic/InstantiateNode.java b/engine/runtime/src/main/java/org/enso/interpreter/node/expression/builtin/interop/generic/InstantiateNode.java index 1a20f1573b..effd14579b 100644 --- a/engine/runtime/src/main/java/org/enso/interpreter/node/expression/builtin/interop/generic/InstantiateNode.java +++ b/engine/runtime/src/main/java/org/enso/interpreter/node/expression/builtin/interop/generic/InstantiateNode.java @@ -16,7 +16,8 @@ import org.enso.interpreter.runtime.error.PanicException; @BuiltinMethod( type = "Polyglot", name = "new", - description = "Instantiates a polyglot constructor.") + description = "Instantiates a polyglot constructor.", + autoRegister = false) public abstract class InstantiateNode extends Node { private @Child InteropLibrary library = diff --git a/engine/runtime/src/main/java/org/enso/interpreter/node/expression/builtin/interop/generic/InvokeNode.java b/engine/runtime/src/main/java/org/enso/interpreter/node/expression/builtin/interop/generic/InvokeNode.java index cbd270d4e2..f7ea8dff44 100644 --- a/engine/runtime/src/main/java/org/enso/interpreter/node/expression/builtin/interop/generic/InvokeNode.java +++ b/engine/runtime/src/main/java/org/enso/interpreter/node/expression/builtin/interop/generic/InvokeNode.java @@ -18,7 +18,8 @@ import org.enso.interpreter.runtime.error.PanicException; @BuiltinMethod( type = "Polyglot", name = "invoke", - description = "Invokes a polyglot method by name, dispatching by the target argument.") + description = "Invokes a polyglot method by name, dispatching by the target argument.", + autoRegister = false) public abstract class InvokeNode extends Node { private @Child InteropLibrary library = InteropLibrary.getFactory().createDispatched(Constants.CacheSizes.BUILTIN_INTEROP_DISPATCH); diff --git a/engine/runtime/src/main/java/org/enso/interpreter/node/expression/builtin/interop/generic/IsLanguageInstalledNode.java b/engine/runtime/src/main/java/org/enso/interpreter/node/expression/builtin/interop/generic/IsLanguageInstalledNode.java index 9bf29399bd..b2031a637c 100644 --- a/engine/runtime/src/main/java/org/enso/interpreter/node/expression/builtin/interop/generic/IsLanguageInstalledNode.java +++ b/engine/runtime/src/main/java/org/enso/interpreter/node/expression/builtin/interop/generic/IsLanguageInstalledNode.java @@ -11,7 +11,8 @@ import org.enso.interpreter.runtime.Context; @BuiltinMethod( type = "Polyglot", name = "is_language_installed", - description = "Checks if a polyglot language is installed in the runtime environment.") + description = "Checks if a polyglot language is installed in the runtime environment.", + autoRegister = false) public abstract class IsLanguageInstalledNode extends Node { static IsLanguageInstalledNode build() { diff --git a/engine/runtime/src/main/java/org/enso/interpreter/node/expression/builtin/interop/generic/ReadArrayElementNode.java b/engine/runtime/src/main/java/org/enso/interpreter/node/expression/builtin/interop/generic/ReadArrayElementNode.java index 836258acb8..c52503f501 100644 --- a/engine/runtime/src/main/java/org/enso/interpreter/node/expression/builtin/interop/generic/ReadArrayElementNode.java +++ b/engine/runtime/src/main/java/org/enso/interpreter/node/expression/builtin/interop/generic/ReadArrayElementNode.java @@ -16,7 +16,8 @@ import org.enso.interpreter.runtime.error.PanicException; @BuiltinMethod( type = "Polyglot", name = "read_array_element", - description = "Read a value from the array specified by the index.") + description = "Read a value from the array specified by the index.", + autoRegister = false) public class ReadArrayElementNode extends Node { private @Child InteropLibrary library = InteropLibrary.getFactory().createDispatched(Constants.CacheSizes.BUILTIN_INTEROP_DISPATCH); diff --git a/engine/runtime/src/main/java/org/enso/interpreter/node/expression/builtin/interop/java/AddToClassPathNode.java b/engine/runtime/src/main/java/org/enso/interpreter/node/expression/builtin/interop/java/AddToClassPathNode.java index 33806ca0b5..24863450d8 100644 --- a/engine/runtime/src/main/java/org/enso/interpreter/node/expression/builtin/interop/java/AddToClassPathNode.java +++ b/engine/runtime/src/main/java/org/enso/interpreter/node/expression/builtin/interop/java/AddToClassPathNode.java @@ -13,22 +13,23 @@ import java.io.File; @BuiltinMethod( type = "Java", name = "add_to_class_path", - description = "Adds a path to the host class path.") + description = "Adds a path to the host class path.", + autoRegister = false) public abstract class AddToClassPathNode extends Node { static AddToClassPathNode build() { return AddToClassPathNodeGen.create(); } + abstract Object execute(Object path); + @CompilerDirectives.TruffleBoundary @Specialization - Object doExecute(Object self, Object path, @Cached ExpectStringNode expectStringNode) { + Object doExecute(Object path, @Cached ExpectStringNode expectStringNode) { Context context = Context.get(this); context .getEnvironment() .addToHostClassPath(context.getTruffleFile(new File(expectStringNode.execute(path)))); return context.getBuiltins().nothing(); } - - abstract Object execute(Object self, Object path); } diff --git a/engine/runtime/src/main/java/org/enso/interpreter/node/expression/builtin/interop/java/LookupClassNode.java b/engine/runtime/src/main/java/org/enso/interpreter/node/expression/builtin/interop/java/LookupClassNode.java index 50a5a4f4c3..58f00fb7f4 100644 --- a/engine/runtime/src/main/java/org/enso/interpreter/node/expression/builtin/interop/java/LookupClassNode.java +++ b/engine/runtime/src/main/java/org/enso/interpreter/node/expression/builtin/interop/java/LookupClassNode.java @@ -7,16 +7,20 @@ import org.enso.interpreter.dsl.BuiltinMethod; import org.enso.interpreter.node.expression.builtin.text.util.ExpectStringNode; import org.enso.interpreter.runtime.Context; -@BuiltinMethod(type = "Java", name = "lookup_class", description = "Looks up a Java symbol.") +@BuiltinMethod( + type = "Java", + name = "lookup_class", + description = "Looks up a Java symbol.", + autoRegister = false) public abstract class LookupClassNode extends Node { static LookupClassNode build() { return LookupClassNodeGen.create(); } @Specialization - Object doExecute(Object self, Object name, @Cached("build()") ExpectStringNode expectStringNode) { + Object doExecute(Object name, @Cached("build()") ExpectStringNode expectStringNode) { return Context.get(this).getEnvironment().lookupHostSymbol(expectStringNode.execute(name)); } - abstract Object execute(Object self, Object name); + abstract Object execute(Object name); } diff --git a/engine/runtime/src/main/java/org/enso/interpreter/node/expression/builtin/io/PrintErrNode.java b/engine/runtime/src/main/java/org/enso/interpreter/node/expression/builtin/io/PrintErrNode.java index f125ea2e2c..7b1a450cbb 100644 --- a/engine/runtime/src/main/java/org/enso/interpreter/node/expression/builtin/io/PrintErrNode.java +++ b/engine/runtime/src/main/java/org/enso/interpreter/node/expression/builtin/io/PrintErrNode.java @@ -22,7 +22,8 @@ import org.enso.interpreter.runtime.type.TypesGen; @BuiltinMethod( type = "IO", name = "print_err", - description = "Prints its argument to standard error.") + description = "Prints its argument to standard error.", + autoRegister = false) public abstract class PrintErrNode extends Node { static PrintErrNode build() { return PrintErrNodeGen.create(); diff --git a/engine/runtime/src/main/java/org/enso/interpreter/node/expression/builtin/io/PrintlnNode.java b/engine/runtime/src/main/java/org/enso/interpreter/node/expression/builtin/io/PrintlnNode.java index fd36af969c..37a77712ce 100644 --- a/engine/runtime/src/main/java/org/enso/interpreter/node/expression/builtin/io/PrintlnNode.java +++ b/engine/runtime/src/main/java/org/enso/interpreter/node/expression/builtin/io/PrintlnNode.java @@ -19,7 +19,11 @@ import org.enso.interpreter.runtime.callable.argument.CallArgumentInfo; import org.enso.interpreter.runtime.state.State; import org.enso.interpreter.runtime.type.TypesGen; -@BuiltinMethod(type = "IO", name = "println", description = "Prints its argument to standard out.") +@BuiltinMethod( + type = "IO", + name = "println", + description = "Prints its argument to standard out.", + autoRegister = false) public abstract class PrintlnNode extends Node { private @Child InvokeCallableNode invokeCallableNode = InvokeCallableNode.build( diff --git a/engine/runtime/src/main/java/org/enso/interpreter/node/expression/builtin/io/ReadlnNode.java b/engine/runtime/src/main/java/org/enso/interpreter/node/expression/builtin/io/ReadlnNode.java index 5bd7c0c123..cf54e1ccb8 100644 --- a/engine/runtime/src/main/java/org/enso/interpreter/node/expression/builtin/io/ReadlnNode.java +++ b/engine/runtime/src/main/java/org/enso/interpreter/node/expression/builtin/io/ReadlnNode.java @@ -10,7 +10,11 @@ import org.enso.interpreter.runtime.Context; import org.enso.interpreter.runtime.data.text.Text; import org.enso.interpreter.runtime.error.PanicException; -@BuiltinMethod(type = "IO", name = "readln", description = "Reads a line from standard in.") +@BuiltinMethod( + type = "IO", + name = "readln", + description = "Reads a line from standard in.", + autoRegister = false) public abstract class ReadlnNode extends Node { static ReadlnNode build() { return ReadlnNodeGen.create(); diff --git a/engine/runtime/src/main/java/org/enso/interpreter/node/expression/builtin/meta/CreateUnresolvedSymbolNode.java b/engine/runtime/src/main/java/org/enso/interpreter/node/expression/builtin/meta/CreateUnresolvedSymbolNode.java index ddfa2fcceb..d3bfac6380 100644 --- a/engine/runtime/src/main/java/org/enso/interpreter/node/expression/builtin/meta/CreateUnresolvedSymbolNode.java +++ b/engine/runtime/src/main/java/org/enso/interpreter/node/expression/builtin/meta/CreateUnresolvedSymbolNode.java @@ -11,7 +11,8 @@ import org.enso.interpreter.runtime.scope.ModuleScope; @BuiltinMethod( type = "Meta", name = "create_unresolved_symbol", - description = "Creates a new unresolved symbol node") + description = "Creates a new unresolved symbol node", + autoRegister = false) public class CreateUnresolvedSymbolNode extends Node { private @Child ExpectStringNode expectStringNode = ExpectStringNode.build(); diff --git a/engine/runtime/src/main/java/org/enso/interpreter/node/expression/builtin/meta/GetAtomConstructorNode.java b/engine/runtime/src/main/java/org/enso/interpreter/node/expression/builtin/meta/GetAtomConstructorNode.java index 5e4617b298..c276381332 100644 --- a/engine/runtime/src/main/java/org/enso/interpreter/node/expression/builtin/meta/GetAtomConstructorNode.java +++ b/engine/runtime/src/main/java/org/enso/interpreter/node/expression/builtin/meta/GetAtomConstructorNode.java @@ -9,7 +9,8 @@ import org.enso.interpreter.runtime.data.Type; @BuiltinMethod( type = "Meta", name = "get_atom_constructor", - description = "Gets the constructor of an atom.") + description = "Gets the constructor of an atom.", + autoRegister = false) public abstract class GetAtomConstructorNode extends Node { abstract Object execute(Object atom); diff --git a/engine/runtime/src/main/java/org/enso/interpreter/node/expression/builtin/meta/GetAtomFieldsNode.java b/engine/runtime/src/main/java/org/enso/interpreter/node/expression/builtin/meta/GetAtomFieldsNode.java index b855048cbd..fb8db90a14 100644 --- a/engine/runtime/src/main/java/org/enso/interpreter/node/expression/builtin/meta/GetAtomFieldsNode.java +++ b/engine/runtime/src/main/java/org/enso/interpreter/node/expression/builtin/meta/GetAtomFieldsNode.java @@ -8,7 +8,8 @@ import org.enso.interpreter.runtime.data.Array; @BuiltinMethod( type = "Meta", name = "get_atom_fields", - description = "Gets the fields of an unresolved atom.") + description = "Gets the fields of an unresolved atom.", + autoRegister = false) public class GetAtomFieldsNode extends Node { Array execute(Atom atom) { return new Array(atom.getFields()); diff --git a/engine/runtime/src/main/java/org/enso/interpreter/node/expression/builtin/meta/GetConstructorFieldNamesNode.java b/engine/runtime/src/main/java/org/enso/interpreter/node/expression/builtin/meta/GetConstructorFieldNamesNode.java index c49137928e..839a209747 100644 --- a/engine/runtime/src/main/java/org/enso/interpreter/node/expression/builtin/meta/GetConstructorFieldNamesNode.java +++ b/engine/runtime/src/main/java/org/enso/interpreter/node/expression/builtin/meta/GetConstructorFieldNamesNode.java @@ -10,7 +10,8 @@ import org.enso.interpreter.runtime.data.text.Text; @BuiltinMethod( type = "Meta", name = "get_constructor_fields", - description = "Gets the field names of a constructor.") + description = "Gets the field names of a constructor.", + autoRegister = false) public class GetConstructorFieldNamesNode extends Node { Array execute(AtomConstructor atom_constructor) { ArgumentDefinition[] fields = atom_constructor.getFields(); diff --git a/engine/runtime/src/main/java/org/enso/interpreter/node/expression/builtin/meta/GetConstructorNameNode.java b/engine/runtime/src/main/java/org/enso/interpreter/node/expression/builtin/meta/GetConstructorNameNode.java index 70603f3cdf..48dd7fff21 100644 --- a/engine/runtime/src/main/java/org/enso/interpreter/node/expression/builtin/meta/GetConstructorNameNode.java +++ b/engine/runtime/src/main/java/org/enso/interpreter/node/expression/builtin/meta/GetConstructorNameNode.java @@ -10,7 +10,8 @@ import org.enso.interpreter.runtime.data.text.Text; @BuiltinMethod( type = "Meta", name = "get_constructor_name", - description = "Gets the name of a constructor.") + description = "Gets the name of a constructor.", + autoRegister = false) public abstract class GetConstructorNameNode extends Node { static GetConstructorNameNode build() { return GetConstructorNameNodeGen.create(); diff --git a/engine/runtime/src/main/java/org/enso/interpreter/node/expression/builtin/meta/GetPolyglotLanguageNode.java b/engine/runtime/src/main/java/org/enso/interpreter/node/expression/builtin/meta/GetPolyglotLanguageNode.java index 73efeb0652..57eb5bcb92 100644 --- a/engine/runtime/src/main/java/org/enso/interpreter/node/expression/builtin/meta/GetPolyglotLanguageNode.java +++ b/engine/runtime/src/main/java/org/enso/interpreter/node/expression/builtin/meta/GetPolyglotLanguageNode.java @@ -9,7 +9,8 @@ import org.enso.interpreter.runtime.data.text.Text; @BuiltinMethod( type = "Meta", name = "get_polyglot_language", - description = "Returns a text representation of a language of origin of a given value.") + description = "Returns a text representation of a language of origin of a given value.", + autoRegister = false) public abstract class GetPolyglotLanguageNode extends Node { static GetPolyglotLanguageNode build() { return GetPolyglotLanguageNodeGen.create(); diff --git a/engine/runtime/src/main/java/org/enso/interpreter/node/expression/builtin/meta/GetQualifiedTypeNameNode.java b/engine/runtime/src/main/java/org/enso/interpreter/node/expression/builtin/meta/GetQualifiedTypeNameNode.java index 64d929c6e7..b3a6204468 100644 --- a/engine/runtime/src/main/java/org/enso/interpreter/node/expression/builtin/meta/GetQualifiedTypeNameNode.java +++ b/engine/runtime/src/main/java/org/enso/interpreter/node/expression/builtin/meta/GetQualifiedTypeNameNode.java @@ -9,7 +9,8 @@ import org.enso.interpreter.runtime.type.Types; @BuiltinMethod( type = "Meta", name = "get_qualified_type_name", - description = "Returns a qualified type name of the given value.") + description = "Returns a qualified type name of the given value.", + autoRegister = false) public class GetQualifiedTypeNameNode extends Node { Text execute(@AcceptsError Object value) { var typeName = Types.getName(value); diff --git a/engine/runtime/src/main/java/org/enso/interpreter/node/expression/builtin/meta/GetSimpleTypeNameNode.java b/engine/runtime/src/main/java/org/enso/interpreter/node/expression/builtin/meta/GetSimpleTypeNameNode.java index 83242ca902..2753d868f0 100644 --- a/engine/runtime/src/main/java/org/enso/interpreter/node/expression/builtin/meta/GetSimpleTypeNameNode.java +++ b/engine/runtime/src/main/java/org/enso/interpreter/node/expression/builtin/meta/GetSimpleTypeNameNode.java @@ -7,7 +7,11 @@ import org.enso.interpreter.dsl.BuiltinMethod; import org.enso.interpreter.node.expression.builtin.text.util.TypeToDisplayTextNode; import org.enso.interpreter.runtime.data.text.Text; -@BuiltinMethod(type = "Meta", name = "get_simple_type_name", description = "Pretty prints a type.") +@BuiltinMethod( + type = "Meta", + name = "get_simple_type_name", + description = "Pretty prints a type.", + autoRegister = false) public class GetSimpleTypeNameNode extends Node { @Child @CompilationFinal TypeToDisplayTextNode displayTypeNode = TypeToDisplayTextNode.build(); diff --git a/engine/runtime/src/main/java/org/enso/interpreter/node/expression/builtin/meta/GetSourceLocationNode.java b/engine/runtime/src/main/java/org/enso/interpreter/node/expression/builtin/meta/GetSourceLocationNode.java index 2f282e4465..81dffce2fe 100644 --- a/engine/runtime/src/main/java/org/enso/interpreter/node/expression/builtin/meta/GetSourceLocationNode.java +++ b/engine/runtime/src/main/java/org/enso/interpreter/node/expression/builtin/meta/GetSourceLocationNode.java @@ -11,7 +11,8 @@ import org.enso.interpreter.runtime.data.text.Text; @BuiltinMethod( type = "Meta", name = "get_source_location_builtin", - description = "Returns a textual representation of the location of the callsite.") + description = "Returns a textual representation of the location of the callsite.", + autoRegister = false) public class GetSourceLocationNode extends Node { Text execute(long frames_to_skip) { diff --git a/engine/runtime/src/main/java/org/enso/interpreter/node/expression/builtin/meta/GetUnresolvedSymbolNameNode.java b/engine/runtime/src/main/java/org/enso/interpreter/node/expression/builtin/meta/GetUnresolvedSymbolNameNode.java index 9210a4eb46..c5cfde0617 100644 --- a/engine/runtime/src/main/java/org/enso/interpreter/node/expression/builtin/meta/GetUnresolvedSymbolNameNode.java +++ b/engine/runtime/src/main/java/org/enso/interpreter/node/expression/builtin/meta/GetUnresolvedSymbolNameNode.java @@ -15,7 +15,8 @@ import org.enso.interpreter.runtime.error.PanicException; @BuiltinMethod( type = "Meta", name = "get_unresolved_symbol_name", - description = "Gets the name of an unresolved symbol") + description = "Gets the name of an unresolved symbol", + autoRegister = false) public abstract class GetUnresolvedSymbolNameNode extends Node { static GetUnresolvedSymbolNameNode build() { return GetUnresolvedSymbolNameNodeGen.create(); diff --git a/engine/runtime/src/main/java/org/enso/interpreter/node/expression/builtin/meta/GetUnresolvedSymbolScopeNode.java b/engine/runtime/src/main/java/org/enso/interpreter/node/expression/builtin/meta/GetUnresolvedSymbolScopeNode.java index ae59422cec..946bb0fab8 100644 --- a/engine/runtime/src/main/java/org/enso/interpreter/node/expression/builtin/meta/GetUnresolvedSymbolScopeNode.java +++ b/engine/runtime/src/main/java/org/enso/interpreter/node/expression/builtin/meta/GetUnresolvedSymbolScopeNode.java @@ -14,7 +14,8 @@ import org.enso.interpreter.runtime.scope.ModuleScope; @BuiltinMethod( type = "Meta", name = "get_unresolved_symbol_scope", - description = "Gets the scope of an unresolved symbol") + description = "Gets the scope of an unresolved symbol", + autoRegister = false) public abstract class GetUnresolvedSymbolScopeNode extends Node { static GetUnresolvedSymbolScopeNode build() { return GetUnresolvedSymbolScopeNodeGen.create(); diff --git a/engine/runtime/src/main/java/org/enso/interpreter/node/expression/builtin/meta/IsAtomConstructorNode.java b/engine/runtime/src/main/java/org/enso/interpreter/node/expression/builtin/meta/IsAtomConstructorNode.java index 1810f8cb16..46abd9e29f 100644 --- a/engine/runtime/src/main/java/org/enso/interpreter/node/expression/builtin/meta/IsAtomConstructorNode.java +++ b/engine/runtime/src/main/java/org/enso/interpreter/node/expression/builtin/meta/IsAtomConstructorNode.java @@ -8,7 +8,8 @@ import org.enso.interpreter.runtime.type.TypesGen; @BuiltinMethod( type = "Meta", name = "is_atom_constructor", - description = "Checks if the argument is a constructor.") + description = "Checks if the argument is a constructor.", + autoRegister = false) public class IsAtomConstructorNode extends Node { boolean execute(@AcceptsError Object value) { return TypesGen.isAtomConstructor(value); diff --git a/engine/runtime/src/main/java/org/enso/interpreter/node/expression/builtin/meta/IsAtomNode.java b/engine/runtime/src/main/java/org/enso/interpreter/node/expression/builtin/meta/IsAtomNode.java index f8b965fc6e..b3aafa2324 100644 --- a/engine/runtime/src/main/java/org/enso/interpreter/node/expression/builtin/meta/IsAtomNode.java +++ b/engine/runtime/src/main/java/org/enso/interpreter/node/expression/builtin/meta/IsAtomNode.java @@ -6,7 +6,11 @@ import org.enso.interpreter.dsl.BuiltinMethod; import org.enso.interpreter.runtime.callable.atom.Atom; import org.enso.interpreter.runtime.data.Type; -@BuiltinMethod(type = "Meta", name = "is_atom", description = "Checks if the argument is an atom") +@BuiltinMethod( + type = "Meta", + name = "is_atom", + description = "Checks if the argument is an atom", + autoRegister = false) public class IsAtomNode extends Node { boolean execute(@AcceptsError Object value) { return value instanceof Atom || value instanceof Type; diff --git a/engine/runtime/src/main/java/org/enso/interpreter/node/expression/builtin/meta/IsErrorNode.java b/engine/runtime/src/main/java/org/enso/interpreter/node/expression/builtin/meta/IsErrorNode.java index 616923417f..cdb5f804b5 100644 --- a/engine/runtime/src/main/java/org/enso/interpreter/node/expression/builtin/meta/IsErrorNode.java +++ b/engine/runtime/src/main/java/org/enso/interpreter/node/expression/builtin/meta/IsErrorNode.java @@ -8,7 +8,8 @@ import org.enso.interpreter.runtime.type.TypesGen; @BuiltinMethod( type = "Meta", name = "is_error", - description = "Checks if the argument is an error.") + description = "Checks if the argument is an error.", + autoRegister = false) public class IsErrorNode extends Node { boolean execute(@AcceptsError Object value) { return TypesGen.isDataflowError(value); diff --git a/engine/runtime/src/main/java/org/enso/interpreter/node/expression/builtin/meta/IsPolyglotNode.java b/engine/runtime/src/main/java/org/enso/interpreter/node/expression/builtin/meta/IsPolyglotNode.java index c388c0c08b..e8818fe233 100644 --- a/engine/runtime/src/main/java/org/enso/interpreter/node/expression/builtin/meta/IsPolyglotNode.java +++ b/engine/runtime/src/main/java/org/enso/interpreter/node/expression/builtin/meta/IsPolyglotNode.java @@ -9,7 +9,8 @@ import org.enso.interpreter.runtime.Context; @BuiltinMethod( type = "Meta", name = "is_polyglot", - description = "Checks if the argument is a polyglot value.") + description = "Checks if the argument is a polyglot value.", + autoRegister = false) public abstract class IsPolyglotNode extends Node { static IsPolyglotNode build() { return IsPolyglotNodeGen.create(); diff --git a/engine/runtime/src/main/java/org/enso/interpreter/node/expression/builtin/meta/IsSameObjectNode.java b/engine/runtime/src/main/java/org/enso/interpreter/node/expression/builtin/meta/IsSameObjectNode.java index 274127c66b..486bddff19 100644 --- a/engine/runtime/src/main/java/org/enso/interpreter/node/expression/builtin/meta/IsSameObjectNode.java +++ b/engine/runtime/src/main/java/org/enso/interpreter/node/expression/builtin/meta/IsSameObjectNode.java @@ -10,7 +10,8 @@ import org.enso.interpreter.dsl.BuiltinMethod; @BuiltinMethod( type = "Meta", name = "is_same_object", - description = "Checks if the two arguments share an underlying reference.") + description = "Checks if the two arguments share an underlying reference.", + autoRegister = false) public abstract class IsSameObjectNode extends Node { public static IsSameObjectNode build() { diff --git a/engine/runtime/src/main/java/org/enso/interpreter/node/expression/builtin/meta/IsUnresolvedSymbolNode.java b/engine/runtime/src/main/java/org/enso/interpreter/node/expression/builtin/meta/IsUnresolvedSymbolNode.java index e5de53ffdc..69f9d0ada5 100644 --- a/engine/runtime/src/main/java/org/enso/interpreter/node/expression/builtin/meta/IsUnresolvedSymbolNode.java +++ b/engine/runtime/src/main/java/org/enso/interpreter/node/expression/builtin/meta/IsUnresolvedSymbolNode.java @@ -8,7 +8,8 @@ import org.enso.interpreter.runtime.type.TypesGen; @BuiltinMethod( type = "Meta", name = "is_unresolved_symbol", - description = "Checks if the argument is an unresolved symbol.") + description = "Checks if the argument is an unresolved symbol.", + autoRegister = false) public class IsUnresolvedSymbolNode extends Node { boolean execute(@AcceptsError Object value) { return TypesGen.isUnresolvedSymbol(value) || TypesGen.isUnresolvedConversion(value); diff --git a/engine/runtime/src/main/java/org/enso/interpreter/node/expression/builtin/meta/NewAtomInstanceNode.java b/engine/runtime/src/main/java/org/enso/interpreter/node/expression/builtin/meta/NewAtomInstanceNode.java index 1d15c06c26..43a25eccef 100644 --- a/engine/runtime/src/main/java/org/enso/interpreter/node/expression/builtin/meta/NewAtomInstanceNode.java +++ b/engine/runtime/src/main/java/org/enso/interpreter/node/expression/builtin/meta/NewAtomInstanceNode.java @@ -11,7 +11,8 @@ import org.enso.interpreter.runtime.callable.atom.AtomConstructor; @BuiltinMethod( type = "Meta", name = "new_atom", - description = "Creates a new atom with given constructor and fields.") + description = "Creates a new atom with given constructor and fields.", + autoRegister = false) public abstract class NewAtomInstanceNode extends Node { static NewAtomInstanceNode build() { diff --git a/engine/runtime/src/main/java/org/enso/interpreter/node/expression/builtin/meta/TypeOfNode.java b/engine/runtime/src/main/java/org/enso/interpreter/node/expression/builtin/meta/TypeOfNode.java index d4799a6985..1e2f5da80d 100644 --- a/engine/runtime/src/main/java/org/enso/interpreter/node/expression/builtin/meta/TypeOfNode.java +++ b/engine/runtime/src/main/java/org/enso/interpreter/node/expression/builtin/meta/TypeOfNode.java @@ -7,7 +7,6 @@ import com.oracle.truffle.api.interop.InteropLibrary; import com.oracle.truffle.api.interop.UnsupportedMessageException; import com.oracle.truffle.api.library.CachedLibrary; import com.oracle.truffle.api.nodes.Node; -import org.enso.interpreter.Constants; import org.enso.interpreter.dsl.AcceptsError; import org.enso.interpreter.dsl.BuiltinMethod; import org.enso.interpreter.epb.runtime.PolyglotProxy; @@ -16,12 +15,12 @@ import org.enso.interpreter.runtime.builtin.Builtins; import org.enso.interpreter.runtime.error.PanicException; import org.enso.interpreter.runtime.library.dispatch.TypesLibrary; import org.enso.interpreter.runtime.number.EnsoBigInteger; -import org.enso.interpreter.runtime.type.TypesGen; @BuiltinMethod( type = "Meta", - name = "type_of_builtin", - description = "Returns the type of a value.") + name = "type_of", + description = "Returns the type of a value.", + autoRegister = false) public abstract class TypeOfNode extends Node { public abstract Object execute(@AcceptsError Object value); diff --git a/engine/runtime/src/main/java/org/enso/interpreter/node/expression/builtin/mutable/CopyNode.java b/engine/runtime/src/main/java/org/enso/interpreter/node/expression/builtin/mutable/CopyNode.java index 3e742796e2..360e1b4548 100644 --- a/engine/runtime/src/main/java/org/enso/interpreter/node/expression/builtin/mutable/CopyNode.java +++ b/engine/runtime/src/main/java/org/enso/interpreter/node/expression/builtin/mutable/CopyNode.java @@ -15,7 +15,11 @@ import org.enso.interpreter.runtime.builtin.Builtins; import org.enso.interpreter.runtime.data.Array; import org.enso.interpreter.runtime.error.PanicException; -@BuiltinMethod(type = "Array", name = "copy", description = "Copies one array to another.") +@BuiltinMethod( + type = "Array", + name = "copy", + description = "Copies one array to another.", + autoRegister = false) public abstract class CopyNode extends Node { static CopyNode build() { diff --git a/engine/runtime/src/main/java/org/enso/interpreter/node/expression/builtin/resource/BracketNode.java b/engine/runtime/src/main/java/org/enso/interpreter/node/expression/builtin/resource/BracketNode.java index aa99454b11..a6e48e4ba3 100644 --- a/engine/runtime/src/main/java/org/enso/interpreter/node/expression/builtin/resource/BracketNode.java +++ b/engine/runtime/src/main/java/org/enso/interpreter/node/expression/builtin/resource/BracketNode.java @@ -27,7 +27,8 @@ import org.enso.interpreter.runtime.type.TypesGen; description = "Takes a computation acquiring a resource, a function taking the resource and closing it," + " and a function performing arbitrary operations on the resource. Ensures closing" - + " the resource, even if an exception is raised in the computation.") + + " the resource, even if an exception is raised in the computation.", + autoRegister = false) public abstract class BracketNode extends Node { private @Child ThunkExecutorNode invokeConstructorNode = ThunkExecutorNode.build(); diff --git a/engine/runtime/src/main/java/org/enso/interpreter/node/expression/builtin/runtime/AllowInputInNode.java b/engine/runtime/src/main/java/org/enso/interpreter/node/expression/builtin/runtime/AllowInputInNode.java index 91c06671f6..5d64fa3baa 100644 --- a/engine/runtime/src/main/java/org/enso/interpreter/node/expression/builtin/runtime/AllowInputInNode.java +++ b/engine/runtime/src/main/java/org/enso/interpreter/node/expression/builtin/runtime/AllowInputInNode.java @@ -11,7 +11,8 @@ import org.enso.interpreter.runtime.state.State; @BuiltinMethod( type = "Runtime", name = "allow_input_in", - description = "Allows input in the specified scope.") + description = "Allows input in the specified scope.", + autoRegister = false) public class AllowInputInNode extends Node { private @Child ThunkExecutorNode thunkExecutorNode = ThunkExecutorNode.build(); private @Child ExpectStringNode expectStringNode = ExpectStringNode.build(); diff --git a/engine/runtime/src/main/java/org/enso/interpreter/node/expression/builtin/runtime/AllowOutputInNode.java b/engine/runtime/src/main/java/org/enso/interpreter/node/expression/builtin/runtime/AllowOutputInNode.java index d0f332990d..3d1caaf578 100644 --- a/engine/runtime/src/main/java/org/enso/interpreter/node/expression/builtin/runtime/AllowOutputInNode.java +++ b/engine/runtime/src/main/java/org/enso/interpreter/node/expression/builtin/runtime/AllowOutputInNode.java @@ -11,7 +11,8 @@ import org.enso.interpreter.runtime.state.State; @BuiltinMethod( type = "Runtime", name = "allow_output_in", - description = "Allows output in the specified scope.") + description = "Allows output in the specified scope.", + autoRegister = false) public class AllowOutputInNode extends Node { private @Child ThunkExecutorNode thunkExecutorNode = ThunkExecutorNode.build(); private @Child ExpectStringNode expectStringNode = ExpectStringNode.build(); diff --git a/engine/runtime/src/main/java/org/enso/interpreter/node/expression/builtin/runtime/GCNode.java b/engine/runtime/src/main/java/org/enso/interpreter/node/expression/builtin/runtime/GCNode.java index 7d96a2ff1a..d8eb0f9f81 100644 --- a/engine/runtime/src/main/java/org/enso/interpreter/node/expression/builtin/runtime/GCNode.java +++ b/engine/runtime/src/main/java/org/enso/interpreter/node/expression/builtin/runtime/GCNode.java @@ -6,10 +6,14 @@ import com.oracle.truffle.api.nodes.Node; import org.enso.interpreter.dsl.BuiltinMethod; import org.enso.interpreter.runtime.Context; -@BuiltinMethod(type = "Runtime", name = "gc", description = "Forces garbage collection") +@BuiltinMethod( + type = "Runtime", + name = "gc", + description = "Forces garbage collection", + autoRegister = false) public abstract class GCNode extends Node { - public abstract Object execute(Object self); + public abstract Object execute(); /** @return A new GCNode. */ public static GCNode build() { diff --git a/engine/runtime/src/main/java/org/enso/interpreter/node/expression/builtin/runtime/GetStackTraceNode.java b/engine/runtime/src/main/java/org/enso/interpreter/node/expression/builtin/runtime/GetStackTraceNode.java index a8030cfa79..1fb7a5a775 100644 --- a/engine/runtime/src/main/java/org/enso/interpreter/node/expression/builtin/runtime/GetStackTraceNode.java +++ b/engine/runtime/src/main/java/org/enso/interpreter/node/expression/builtin/runtime/GetStackTraceNode.java @@ -9,7 +9,8 @@ import org.enso.interpreter.runtime.error.PanicException; @BuiltinMethod( type = "Runtime", name = "primitive_get_stack_trace", - description = "Gets the current execution stacktrace.") + description = "Gets the current execution stacktrace.", + autoRegister = false) public class GetStackTraceNode extends Node { Array execute() { var exception = new PanicException("Stacktrace", this); diff --git a/engine/runtime/src/main/java/org/enso/interpreter/node/expression/builtin/runtime/NoInlineNode.java b/engine/runtime/src/main/java/org/enso/interpreter/node/expression/builtin/runtime/NoInlineNode.java index af903cbc8a..6f96e8040e 100644 --- a/engine/runtime/src/main/java/org/enso/interpreter/node/expression/builtin/runtime/NoInlineNode.java +++ b/engine/runtime/src/main/java/org/enso/interpreter/node/expression/builtin/runtime/NoInlineNode.java @@ -11,7 +11,8 @@ import org.enso.interpreter.runtime.state.State; @BuiltinMethod( type = "Runtime", name = "no_inline", - description = "Runs its argument without the possibility of getting inlined.") + description = "Runs its argument without the possibility of getting inlined.", + autoRegister = false) public class NoInlineNode extends Node { private @Child ThunkExecutorNode thunkExecutorNode = ThunkExecutorNode.build(); diff --git a/engine/runtime/src/main/java/org/enso/interpreter/node/expression/builtin/runtime/NoInlineWithArgNode.java b/engine/runtime/src/main/java/org/enso/interpreter/node/expression/builtin/runtime/NoInlineWithArgNode.java index 8ac4c2b8d3..f7d0467fff 100644 --- a/engine/runtime/src/main/java/org/enso/interpreter/node/expression/builtin/runtime/NoInlineWithArgNode.java +++ b/engine/runtime/src/main/java/org/enso/interpreter/node/expression/builtin/runtime/NoInlineWithArgNode.java @@ -14,7 +14,8 @@ import org.enso.interpreter.runtime.state.State; type = "Runtime", name = "no_inline_with_arg", description = - "Runs its first argument applied to the second argument without the possibility of the call or its argument getting inlined.") + "Runs its first argument applied to the second argument without the possibility of the call or its argument getting inlined.", + autoRegister = false) public class NoInlineWithArgNode extends Node { private @Child InvokeCallableNode invokeCallableNode; diff --git a/engine/runtime/src/main/java/org/enso/interpreter/node/expression/builtin/state/GetStateNode.java b/engine/runtime/src/main/java/org/enso/interpreter/node/expression/builtin/state/GetStateNode.java index 004f8cbbb5..11c0bed5c2 100644 --- a/engine/runtime/src/main/java/org/enso/interpreter/node/expression/builtin/state/GetStateNode.java +++ b/engine/runtime/src/main/java/org/enso/interpreter/node/expression/builtin/state/GetStateNode.java @@ -15,7 +15,8 @@ import org.enso.interpreter.runtime.state.State; @BuiltinMethod( type = "State", name = "get", - description = "Returns the current value of monadic state.") + description = "Returns the current value of monadic state.", + autoRegister = false) @ReportPolymorphism public abstract class GetStateNode extends Node { static GetStateNode build() { diff --git a/engine/runtime/src/main/java/org/enso/interpreter/node/expression/builtin/state/PutStateNode.java b/engine/runtime/src/main/java/org/enso/interpreter/node/expression/builtin/state/PutStateNode.java index e2a80e1b3b..3b364300e1 100644 --- a/engine/runtime/src/main/java/org/enso/interpreter/node/expression/builtin/state/PutStateNode.java +++ b/engine/runtime/src/main/java/org/enso/interpreter/node/expression/builtin/state/PutStateNode.java @@ -12,7 +12,11 @@ import org.enso.interpreter.runtime.Context; import org.enso.interpreter.runtime.error.PanicException; import org.enso.interpreter.runtime.state.State; -@BuiltinMethod(type = "State", name = "put", description = "Updates the value of monadic state.") +@BuiltinMethod( + type = "State", + name = "put", + description = "Updates the value of monadic state.", + autoRegister = false) @ReportPolymorphism public abstract class PutStateNode extends Node { static PutStateNode build() { diff --git a/engine/runtime/src/main/java/org/enso/interpreter/node/expression/builtin/state/RunStateNode.java b/engine/runtime/src/main/java/org/enso/interpreter/node/expression/builtin/state/RunStateNode.java index 26878bfd70..8904085b0d 100644 --- a/engine/runtime/src/main/java/org/enso/interpreter/node/expression/builtin/state/RunStateNode.java +++ b/engine/runtime/src/main/java/org/enso/interpreter/node/expression/builtin/state/RunStateNode.java @@ -15,7 +15,8 @@ import org.enso.interpreter.runtime.state.State; @BuiltinMethod( type = "State", name = "run", - description = "Runs a stateful computation in a local state environment.") + description = "Runs a stateful computation in a local state environment.", + autoRegister = false) @ReportPolymorphism public abstract class RunStateNode extends Node { static RunStateNode build() { diff --git a/engine/runtime/src/main/java/org/enso/interpreter/node/expression/builtin/text/OptimizeNode.java b/engine/runtime/src/main/java/org/enso/interpreter/node/expression/builtin/text/OptimizeNode.java index 0f0109c1ec..b25849c7f5 100644 --- a/engine/runtime/src/main/java/org/enso/interpreter/node/expression/builtin/text/OptimizeNode.java +++ b/engine/runtime/src/main/java/org/enso/interpreter/node/expression/builtin/text/OptimizeNode.java @@ -10,7 +10,8 @@ import org.enso.interpreter.runtime.data.text.Text; @BuiltinMethod( type = "Prim_Text_Helper", name = "optimize", - description = "Forces flattening of a text value, for testing purposes.") + description = "Forces flattening of a text value, for testing purposes.", + autoRegister = false) public abstract class OptimizeNode extends Node { private @Child ToJavaStringNode toJavaStringNode = ToJavaStringNode.build(); diff --git a/engine/runtime/src/main/java/org/enso/interpreter/node/expression/builtin/thread/WithInterruptHandlerNode.java b/engine/runtime/src/main/java/org/enso/interpreter/node/expression/builtin/thread/WithInterruptHandlerNode.java index fde33bd47e..e98c451294 100644 --- a/engine/runtime/src/main/java/org/enso/interpreter/node/expression/builtin/thread/WithInterruptHandlerNode.java +++ b/engine/runtime/src/main/java/org/enso/interpreter/node/expression/builtin/thread/WithInterruptHandlerNode.java @@ -11,7 +11,8 @@ import org.enso.interpreter.runtime.state.State; @BuiltinMethod( type = "Thread", name = "with_interrupt_handler", - description = "Runs a computation with a handler for thread interrupts.") + description = "Runs a computation with a handler for thread interrupts.", + autoRegister = false) public class WithInterruptHandlerNode extends Node { private @Child ThunkExecutorNode actExecutorNode = ThunkExecutorNode.build(); private @Child ThunkExecutorNode handlerExecutorNode = ThunkExecutorNode.build(); diff --git a/engine/runtime/src/main/java/org/enso/interpreter/node/expression/builtin/unsafe/SetAtomFieldNode.java b/engine/runtime/src/main/java/org/enso/interpreter/node/expression/builtin/unsafe/SetAtomFieldNode.java index 00bff497e3..22d72bc874 100644 --- a/engine/runtime/src/main/java/org/enso/interpreter/node/expression/builtin/unsafe/SetAtomFieldNode.java +++ b/engine/runtime/src/main/java/org/enso/interpreter/node/expression/builtin/unsafe/SetAtomFieldNode.java @@ -7,7 +7,8 @@ import org.enso.interpreter.runtime.callable.atom.Atom; @BuiltinMethod( type = "Unsafe", name = "set_atom_field", - description = "Unsafely, in place, sets the value of an atom field by index.") + description = "Unsafely, in place, sets the value of an atom field by index.", + autoRegister = false) public class SetAtomFieldNode extends Node { Atom execute(Atom atom, long index, Object value) { atom.getFields()[(int) index] = value; diff --git a/engine/runtime/src/main/java/org/enso/interpreter/runtime/Module.java b/engine/runtime/src/main/java/org/enso/interpreter/runtime/Module.java index cd681592b8..2149339c94 100644 --- a/engine/runtime/src/main/java/org/enso/interpreter/runtime/Module.java +++ b/engine/runtime/src/main/java/org/enso/interpreter/runtime/Module.java @@ -27,6 +27,7 @@ import org.enso.compiler.core.IR; import org.enso.interpreter.node.callable.dispatch.CallOptimiserNode; import org.enso.interpreter.node.callable.dispatch.LoopingCallOptimiserNode; import org.enso.interpreter.runtime.builtin.Builtins; +import org.enso.interpreter.runtime.builtin.BuiltinFunction; import org.enso.interpreter.runtime.callable.CallerInfo; import org.enso.interpreter.runtime.callable.function.Function; import org.enso.interpreter.runtime.data.Array; @@ -571,14 +572,14 @@ public final class Module implements TruffleObject { throws ArityException, UnsupportedTypeException { String expr = Types.extractArguments(args, String.class); Builtins builtins = context.getBuiltins(); - Function eval = + BuiltinFunction eval = builtins .getBuiltinFunction( builtins.debug(), Builtins.MethodNames.Debug.EVAL, context.getLanguage()) .orElseThrow(); CallerInfo callerInfo = new CallerInfo(null, LocalScope.root(), scope); return callOptimiserNode.executeDispatch( - eval, + eval.getFunction(), callerInfo, context.emptyState(), new Object[] {builtins.debug(), Text.create(expr)}); diff --git a/engine/runtime/src/main/java/org/enso/interpreter/runtime/builtin/BuiltinFunction.java b/engine/runtime/src/main/java/org/enso/interpreter/runtime/builtin/BuiltinFunction.java new file mode 100644 index 0000000000..d40c36e31a --- /dev/null +++ b/engine/runtime/src/main/java/org/enso/interpreter/runtime/builtin/BuiltinFunction.java @@ -0,0 +1,23 @@ +package org.enso.interpreter.runtime.builtin; + +import org.enso.interpreter.runtime.callable.function.Function; + +/** BuiltinFunction encapsulates information about a builtin runtime function and its metadata. */ +public class BuiltinFunction { + // Note: ideally BuiltinFunction would be a record but there appears to be a bug in frgaal. + private Function fun; + private boolean autoRegister; + + public BuiltinFunction(Function fun, boolean autoRegister) { + this.fun = fun; + this.autoRegister = autoRegister; + } + + public boolean isAutoRegister() { + return this.autoRegister; + } + + public Function getFunction() { + return this.fun; + } +} diff --git a/engine/runtime/src/main/java/org/enso/interpreter/runtime/builtin/Builtins.java b/engine/runtime/src/main/java/org/enso/interpreter/runtime/builtin/Builtins.java index 10339e9013..89e41a4eb3 100644 --- a/engine/runtime/src/main/java/org/enso/interpreter/runtime/builtin/Builtins.java +++ b/engine/runtime/src/main/java/org/enso/interpreter/runtime/builtin/Builtins.java @@ -3,12 +3,15 @@ package org.enso.interpreter.runtime.builtin; import com.oracle.truffle.api.CompilerDirectives; import java.lang.reflect.Constructor; +import java.util.AbstractMap; import java.util.ArrayList; +import java.util.Arrays; import java.util.HashMap; import java.util.List; import java.util.Map; import java.util.Optional; + import org.enso.compiler.Passes; import org.enso.compiler.context.FreshNameSupply; import org.enso.compiler.exception.CompilerError; @@ -44,14 +47,13 @@ import java.io.InputStreamReader; import java.lang.reflect.InvocationTargetException; import java.lang.reflect.Method; import java.nio.charset.StandardCharsets; -import java.util.*; import java.util.stream.Collectors; /** Container class for static predefined atoms, methods, and their containing scope. */ public class Builtins { private static final List> loadedBuiltinConstructors; - private static final Map loadedBbuiltinMethods; + private static final Map loadedBbuiltinMethods; static { loadedBuiltinConstructors = readBuiltinTypes(); @@ -70,7 +72,7 @@ public class Builtins { } private final Map, Builtin> builtins; - private final Map> builtinMethodNodes; + private final Map> builtinMethodNodes; private final Map builtinsByName; private final Error error; @@ -162,19 +164,18 @@ public class Builtins { for (Builtin builtin : builtins.values()) { var type = builtin.getType(); String tpeName = type.getName(); - Map methods = builtinMethodNodes.get(tpeName); + Map methods = builtinMethodNodes.get(tpeName); if (methods != null) { - methods.forEach( - (methodName, meth) -> { - Optional fun; - try { - fun = Optional.ofNullable((Function) meth.invoke(null, language)); - } catch (Exception e) { - e.printStackTrace(); - fun = Optional.empty(); - } - fun.ifPresent(f -> scope.registerMethod(type, methodName, f)); - }); + // Register a builtin method iff it is marked as auto-register. + // Methods can only register under a type or, if we deal with a static method, it's eigen-type. + // Such builtins are available on certain types without importing the whole stdlib, e.g. Any or Number. + methods.entrySet().stream().forEach(entry -> { + Type tpe = entry.getValue().isAutoRegister ? (!entry.getValue().isStatic() ? type : type.getEigentype()) : null; + if (tpe != null) { + Optional fun = entry.getValue().toFunction(language); + fun.ifPresent(f -> scope.registerMethod(tpe, entry.getKey(), f.getFunction())); + } + }); } } } @@ -209,14 +210,13 @@ public class Builtins { } /** - * Returns a map of Builtin Types and their instances. + * Returns a list of supported builtins. * *

Builtin types are marked via @BuiltinType annotation. THe metdata file represents a single * builtin type per row. The format of the row is as follows: ::[,,...] where the last column gives a * list of optional type's fields. * - * @return map of builtin types' classes and their instances */ private static List> readBuiltinTypes() { ClassLoader classLoader = Builtins.class.getClassLoader(); @@ -281,12 +281,12 @@ public class Builtins { * @param scope Builtins scope * @return A map of builtin method nodes per builtin type name */ - private Map> readBuiltinMethodsMetadata( - Map classes, ModuleScope scope) { + private Map> readBuiltinMethodsMetadata( + Map classes, ModuleScope scope) { - Map> methodNodes = new HashMap<>(); + Map> methodNodes = new HashMap<>(); classes.forEach( - (fullBuiltinName, meth) -> { + (fullBuiltinName, builtin) -> { String[] builtinName = fullBuiltinName.split("\\."); if (builtinName.length != 2) { throw new CompilerError("Invalid builtin metadata for " + fullBuiltinName); @@ -296,22 +296,22 @@ public class Builtins { Optional.ofNullable(scope.getTypes().get(builtinMethodOwner)) .ifPresentOrElse( constr -> { - Map atomNodes = methodNodes.get(builtinMethodOwner); + Map atomNodes = methodNodes.get(builtinMethodOwner); if (atomNodes == null) { atomNodes = new HashMap<>(); // TODO: move away from String Map once Builtins are gone methodNodes.put(constr.getName(), atomNodes); } - atomNodes.put(builtinMethodName, meth); + atomNodes.put(builtinMethodName, builtin); }, () -> { - Map atomNodes = methodNodes.get(builtinMethodOwner); + Map atomNodes = methodNodes.get(builtinMethodOwner); if (atomNodes == null) { atomNodes = new HashMap<>(); // TODO: move away from String Map once Builtins are gone methodNodes.put(builtinMethodOwner, atomNodes); } - atomNodes.put(builtinMethodName, meth); + atomNodes.put(builtinMethodName, builtin); }); }); return methodNodes; @@ -326,7 +326,7 @@ public class Builtins { * * @return A map of builtin method nodes per builtin type name */ - private static Map readBuiltinMethodsMethods() { + private static Map readBuiltinMethodsMethods() { ClassLoader classLoader = Builtins.class.getClassLoader(); List lines; try (InputStream resource = classLoader.getResourceAsStream(MethodDefinition.META_PATH)) { @@ -340,29 +340,32 @@ public class Builtins { } return lines.stream() - .map( - line -> { - String[] builtinMeta = line.split(":"); - if (builtinMeta.length != 2) { - throw new CompilerError("Invalid builtin metadata in: " + line); - } - String[] builtinName = builtinMeta[0].split("\\."); - if (builtinName.length != 2) { - throw new CompilerError("Invalid builtin metadata in : " + line); - } - try { - @SuppressWarnings("unchecked") - Class clazz = - (Class) Class.forName(builtinMeta[1]); - Method meth = clazz.getMethod("makeFunction", Language.class); - // methodNodes.put(builtinMeta[0], meth); - return new AbstractMap.SimpleEntry(builtinMeta[0], meth); - } catch (ClassNotFoundException | NoSuchMethodException e) { - e.printStackTrace(); - throw new CompilerError("Invalid builtin method " + line); - } - }) - .collect(Collectors.toMap(Map.Entry::getKey, Map.Entry::getValue)); + .map( + line -> { + String[] builtinMeta = line.split(":"); + if (builtinMeta.length != 4) { + throw new CompilerError("Invalid builtin metadata in: " + line); + } + String[] builtinName = builtinMeta[0].split("\\."); + if (builtinName.length != 2) { + throw new CompilerError("Invalid builtin metadata in : " + line); + } + boolean isStatic = builtinMeta.length == 3 ? java.lang.Boolean.valueOf(builtinMeta[2]) : false; + boolean isAutoRegister = builtinMeta.length == 4 && java.lang.Boolean.valueOf(builtinMeta[3]); + + try { + @SuppressWarnings("unchecked") + Class clazz = + (Class) Class.forName(builtinMeta[1]); + Method meth = clazz.getMethod("makeFunction", Language.class); + LoadedBuiltinMethod meta = new LoadedBuiltinMethod(meth, isStatic, isAutoRegister); + return new AbstractMap.SimpleEntry(builtinMeta[0], meta); + } catch (ClassNotFoundException | NoSuchMethodException e) { + e.printStackTrace(); + throw new CompilerError("Invalid builtin method " + line); + } + }) + .collect(Collectors.toMap(Map.Entry::getKey, Map.Entry::getValue)); } /** @@ -374,21 +377,16 @@ public class Builtins { * @return A non-empty function under the given name, if it exists. An empty value if no such * builtin method was ever registerd */ - public Optional getBuiltinFunction(String type, String methodName, Language language) { + public Optional getBuiltinFunction(String type, String methodName, Language language) { // TODO: move away from String mapping once Builtins is gone - Map atomNodes = builtinMethodNodes.get(type); + Map atomNodes = builtinMethodNodes.get(type); if (atomNodes == null) return Optional.empty(); - Method meth = atomNodes.get(methodName); - if (meth == null) return Optional.empty(); - try { - return Optional.ofNullable((Function) meth.invoke(null, language)); - } catch (IllegalAccessException | InvocationTargetException e) { - e.printStackTrace(); - return Optional.empty(); - } + LoadedBuiltinMethod builtin = atomNodes.get(methodName); + if (builtin == null) return Optional.empty(); + return builtin.toFunction(language); } - public Optional getBuiltinFunction(Type type, String methodName, Language language) { + public Optional getBuiltinFunction(Type type, String methodName, Language language) { return getBuiltinFunction(type.getName(), methodName, language); } @@ -611,4 +609,16 @@ public class Builtins { public Type fromTypeSystem(String typeName) { return TypesFromProxy.fromTypeSystem(this, typeName); } + + private record LoadedBuiltinMethod(Method meth, boolean isStatic, boolean isAutoRegister) { + Optional toFunction(Language language) { + try { + return Optional.ofNullable((Function) meth.invoke(null, language)).map(f-> new BuiltinFunction(f, isAutoRegister)); + } catch (Exception e) { + e.printStackTrace(); + return Optional.empty(); + } + } + } + } diff --git a/engine/runtime/src/main/java/org/enso/interpreter/runtime/data/Array.java b/engine/runtime/src/main/java/org/enso/interpreter/runtime/data/Array.java index 86f42c5690..e76d51f319 100644 --- a/engine/runtime/src/main/java/org/enso/interpreter/runtime/data/Array.java +++ b/engine/runtime/src/main/java/org/enso/interpreter/runtime/data/Array.java @@ -26,7 +26,7 @@ public final class Array implements TruffleObject { * * @param items the element values */ - @Builtin.Method(expandVarargs = 4, description = "Creates an array with given elements.") + @Builtin.Method(expandVarargs = 4, description = "Creates an array with given elements.", autoRegister = false) public Array(Object... items) { this.items = items; } @@ -36,7 +36,7 @@ public final class Array implements TruffleObject { * * @param size the size of the created array. */ - @Builtin.Method(description = "Creates an uninitialized array of a given size.") + @Builtin.Method(description = "Creates an uninitialized array of a given size.", autoRegister = false) public Array(long size) { this.items = new Object[(int) size]; } @@ -80,7 +80,7 @@ public final class Array implements TruffleObject { } /** @return an empty array */ - @Builtin.Method(description = "Creates an empty Array") + @Builtin.Method(description = "Creates an empty Array", autoRegister = false) public static Object empty() { return new Array(); } diff --git a/engine/runtime/src/main/java/org/enso/interpreter/runtime/data/EnsoDate.java b/engine/runtime/src/main/java/org/enso/interpreter/runtime/data/EnsoDate.java index 5ded543d45..0e6afe2225 100644 --- a/engine/runtime/src/main/java/org/enso/interpreter/runtime/data/EnsoDate.java +++ b/engine/runtime/src/main/java/org/enso/interpreter/runtime/data/EnsoDate.java @@ -31,13 +31,13 @@ public final class EnsoDate implements TruffleObject { this.date = date; } - @Builtin.Method(description = "Return current Date") + @Builtin.Method(description = "Return current Date", autoRegister = false) @CompilerDirectives.TruffleBoundary public static EnsoDate now() { return new EnsoDate(LocalDate.now()); } - @Builtin.Method(name = "internal_parse", description = "Constructs a new Date from text with optional pattern") + @Builtin.Method(name = "parse_builtin", description = "Constructs a new Date from text with optional pattern", autoRegister = false) @Builtin.Specialize @Builtin.WrapException(from = DateTimeParseException.class, to = PolyglotError.class) @CompilerDirectives.TruffleBoundary @@ -51,7 +51,7 @@ public final class EnsoDate implements TruffleObject { } } - @Builtin.Method(name = "internal_new", description = "Constructs a new Date from a year, month, and day") + @Builtin.Method(name = "new_builtin", description = "Constructs a new Date from a year, month, and day", autoRegister = false) @Builtin.WrapException(from = DateTimeException.class, to = PolyglotError.class) @CompilerDirectives.TruffleBoundary public static EnsoDate create(long year, long month, long day) { diff --git a/engine/runtime/src/main/java/org/enso/interpreter/runtime/data/EnsoDateTime.java b/engine/runtime/src/main/java/org/enso/interpreter/runtime/data/EnsoDateTime.java index 7a2e764e75..72e0f5782a 100644 --- a/engine/runtime/src/main/java/org/enso/interpreter/runtime/data/EnsoDateTime.java +++ b/engine/runtime/src/main/java/org/enso/interpreter/runtime/data/EnsoDateTime.java @@ -34,12 +34,15 @@ public final class EnsoDateTime implements TruffleObject { this.dateTime = dateTime; } - @Builtin.Method(name = "epoch_start", description = "Return the Enso start of the Epoch") + @Builtin.Method( + name = "epoch_start", + description = "Return the Enso start of the Epoch", + autoRegister = false) public static EnsoDateTime epochStart() { return epochStart; } - @Builtin.Method(description = "Return current DateTime") + @Builtin.Method(description = "Return current DateTime", autoRegister = false) @CompilerDirectives.TruffleBoundary public static EnsoDateTime now() { return new EnsoDateTime(ZonedDateTime.now()); @@ -62,7 +65,8 @@ public final class EnsoDateTime implements TruffleObject { */ @Builtin.Method( name = "parse_builtin", - description = "Constructs a new DateTime from text with optional pattern") + description = "Constructs a new DateTime from text with optional pattern", + autoRegister = false) @Builtin.Specialize @Builtin.WrapException(from = DateTimeParseException.class, to = PolyglotError.class) @CompilerDirectives.TruffleBoundary @@ -78,7 +82,8 @@ public final class EnsoDateTime implements TruffleObject { @Builtin.Method( name = "new_builtin", - description = "Constructs a new Date from a year, month, and day") + description = "Constructs a new Date from a year, month, and day", + autoRegister = false) @Builtin.WrapException(from = DateTimeException.class, to = PolyglotError.class) @CompilerDirectives.TruffleBoundary public static EnsoDateTime create( @@ -168,16 +173,14 @@ public final class EnsoDateTime implements TruffleObject { } @Builtin.Method( - name = "to_localtime_builtin", + name = "time_of_day", description = "Return the localtime of this date time value.") @CompilerDirectives.TruffleBoundary public EnsoTimeOfDay toLocalTime() { return new EnsoTimeOfDay(dateTime.toLocalTime()); } - @Builtin.Method( - name = "to_localdate_builtin", - description = "Return the localdate of this date time value.") + @Builtin.Method(name = "date", description = "Return the localdate of this date time value.") @CompilerDirectives.TruffleBoundary public EnsoDate toLocalDate() { return new EnsoDate(dateTime.toLocalDate()); @@ -189,15 +192,6 @@ public final class EnsoDateTime implements TruffleObject { return new EnsoDateTime(dateTime.withZoneSameInstant(zone.asTimeZone())); } - @Builtin.Method( - name = "to_time_builtin", - description = "Combine this day with time to create a point in time.") - @CompilerDirectives.TruffleBoundary - public EnsoDateTime toTime(EnsoTimeOfDay timeOfDay, EnsoTimeZone zone) { - return new EnsoDateTime( - dateTime.toLocalDate().atTime(timeOfDay.asTime()).atZone(zone.asTimeZone())); - } - @Builtin.Method(description = "Return this datetime to the datetime in the provided time zone.") @CompilerDirectives.TruffleBoundary public Text toText() { diff --git a/engine/runtime/src/main/java/org/enso/interpreter/runtime/data/EnsoDuration.java b/engine/runtime/src/main/java/org/enso/interpreter/runtime/data/EnsoDuration.java index e07192a617..e505b9ba86 100644 --- a/engine/runtime/src/main/java/org/enso/interpreter/runtime/data/EnsoDuration.java +++ b/engine/runtime/src/main/java/org/enso/interpreter/runtime/data/EnsoDuration.java @@ -1,6 +1,5 @@ package org.enso.interpreter.runtime.data; -import com.oracle.truffle.api.CompilerDirectives; import com.oracle.truffle.api.CompilerDirectives.TruffleBoundary; import com.oracle.truffle.api.interop.InteropLibrary; import com.oracle.truffle.api.interop.TruffleObject; @@ -43,7 +42,8 @@ public final class EnsoDuration implements TruffleObject { @Builtin.Method( name = "new_builtin", description = - "Constructs a new Duration from hours, minutes, seconds, milliseconds and nanoseconds") + "Constructs a new Duration from hours, minutes, seconds, milliseconds and nanoseconds", + autoRegister = false) @TruffleBoundary public static EnsoDuration create( long hours, long minutes, long seconds, long milliseconds, long nanoseconds) { @@ -59,7 +59,8 @@ public final class EnsoDuration implements TruffleObject { @Builtin.Method( name = "between_builtin", description = - "Construct a new Duration that is between the given start date inclusive, and end date exclusive") + "Construct a new Duration that is between the given start date inclusive, and end date exclusive", + autoRegister = false) @Builtin.Specialize @TruffleBoundary public static EnsoDuration between( diff --git a/engine/runtime/src/main/java/org/enso/interpreter/runtime/data/EnsoFile.java b/engine/runtime/src/main/java/org/enso/interpreter/runtime/data/EnsoFile.java index 8b17924f09..d2308d94e6 100644 --- a/engine/runtime/src/main/java/org/enso/interpreter/runtime/data/EnsoFile.java +++ b/engine/runtime/src/main/java/org/enso/interpreter/runtime/data/EnsoFile.java @@ -224,7 +224,8 @@ public final class EnsoFile implements TruffleObject { @Builtin.Method( name = "get_file", description = - "Takes the text representation of a path and returns a TruffleFile corresponding to it.") + "Takes the text representation of a path and returns a TruffleFile corresponding to it.", + autoRegister = false) @Builtin.Specialize @CompilerDirectives.TruffleBoundary public static EnsoFile fromString(Context context, String path) { @@ -234,7 +235,8 @@ public final class EnsoFile implements TruffleObject { @Builtin.Method( name = "get_cwd", - description = "A file corresponding to the current working directory.") + description = "A file corresponding to the current working directory.", + autoRegister = false) @Builtin.Specialize @CompilerDirectives.TruffleBoundary public static EnsoFile currentDirectory(Context context) { @@ -242,7 +244,10 @@ public final class EnsoFile implements TruffleObject { return new EnsoFile(file); } - @Builtin.Method(name = "home", description = "Gets the user's system-defined home directory.") + @Builtin.Method( + name = "home", + description = "Gets the user's system-defined home directory.", + autoRegister = false) @Builtin.Specialize @CompilerDirectives.TruffleBoundary public static EnsoFile userHome(Context context) { diff --git a/engine/runtime/src/main/java/org/enso/interpreter/runtime/data/EnsoTimeOfDay.java b/engine/runtime/src/main/java/org/enso/interpreter/runtime/data/EnsoTimeOfDay.java index 35c08ffafa..385d8c44fc 100644 --- a/engine/runtime/src/main/java/org/enso/interpreter/runtime/data/EnsoTimeOfDay.java +++ b/engine/runtime/src/main/java/org/enso/interpreter/runtime/data/EnsoTimeOfDay.java @@ -32,7 +32,8 @@ public final class EnsoTimeOfDay implements TruffleObject { @Builtin.Method( name = "parse_builtin", - description = "Constructs a new DateTime from text with optional pattern") + description = "Constructs a new DateTime from text with optional pattern", + autoRegister = false) @Builtin.Specialize @Builtin.WrapException(from = DateTimeParseException.class, to = PolyglotError.class) @CompilerDirectives.TruffleBoundary @@ -40,7 +41,10 @@ public final class EnsoTimeOfDay implements TruffleObject { return new EnsoTimeOfDay(LocalTime.parse(text)); } - @Builtin.Method(name = "new_builtin", description = "Constructs a new Time_OF_Day from an hour") + @Builtin.Method( + name = "new_builtin", + description = "Constructs a new Time_OF_Day from an hour", + autoRegister = false) @Builtin.WrapException(from = DateTimeException.class, to = PolyglotError.class) @CompilerDirectives.TruffleBoundary public static EnsoTimeOfDay create(long hour, long minute, long second, long nanosecond) { @@ -52,7 +56,7 @@ public final class EnsoTimeOfDay implements TruffleObject { Math.toIntExact(nanosecond))); } - @Builtin.Method(description = "Gets a value of hour") + @Builtin.Method(description = "Gets a value of hour", autoRegister = false) @CompilerDirectives.TruffleBoundary public static EnsoTimeOfDay now() { return new EnsoTimeOfDay(LocalTime.now()); @@ -107,7 +111,7 @@ public final class EnsoTimeOfDay implements TruffleObject { } @Builtin.Method( - name = "to_time_builtin", + name = "to_date_time_builtin", description = "Combine this time of day with a date to create a point in time.") @CompilerDirectives.TruffleBoundary public EnsoDateTime toTime(EnsoDate date, EnsoTimeZone zone) { diff --git a/engine/runtime/src/main/java/org/enso/interpreter/runtime/data/EnsoTimeZone.java b/engine/runtime/src/main/java/org/enso/interpreter/runtime/data/EnsoTimeZone.java index 85cddc9566..af12574438 100644 --- a/engine/runtime/src/main/java/org/enso/interpreter/runtime/data/EnsoTimeZone.java +++ b/engine/runtime/src/main/java/org/enso/interpreter/runtime/data/EnsoTimeZone.java @@ -15,7 +15,6 @@ import org.enso.interpreter.runtime.library.dispatch.TypesLibrary; import java.time.DateTimeException; import java.time.ZoneId; import java.time.ZoneOffset; -import java.time.format.DateTimeFormatter; import java.time.zone.ZoneRulesException; @ExportLibrary(InteropLibrary.class) @@ -34,7 +33,10 @@ public final class EnsoTimeZone implements TruffleObject { return Text.create(this.zone.getId()); } - @Builtin.Method(name = "parse_builtin", description = "Parse the ID producing a Time_Zone.") + @Builtin.Method( + name = "parse_builtin", + description = "Parse the ID producing a Time_Zone.", + autoRegister = false) @Builtin.Specialize @Builtin.WrapException(from = ZoneRulesException.class, to = PolyglotError.class) @CompilerDirectives.TruffleBoundary @@ -45,7 +47,8 @@ public final class EnsoTimeZone implements TruffleObject { @Builtin.Method( name = "new_builtin", description = - "Obtains an instance of `Time_Zone` using an offset in hours, minutes and seconds from the UTC zone.") + "Obtains an instance of `Time_Zone` using an offset in hours, minutes and seconds from the UTC zone.", + autoRegister = false) @Builtin.WrapException(from = DateTimeException.class, to = PolyglotError.class) @CompilerDirectives.TruffleBoundary public static EnsoTimeZone create(long hours, long minutes, long seconds) { @@ -54,7 +57,10 @@ public final class EnsoTimeZone implements TruffleObject { Math.toIntExact(hours), Math.toIntExact(minutes), Math.toIntExact(seconds))); } - @Builtin.Method(name = "system", description = "The system default timezone.") + @Builtin.Method( + name = "system", + description = "The system default timezone.", + autoRegister = false) @CompilerDirectives.TruffleBoundary public static EnsoTimeZone system() { return new EnsoTimeZone(ZoneId.systemDefault()); diff --git a/engine/runtime/src/main/java/org/enso/interpreter/runtime/data/Ref.java b/engine/runtime/src/main/java/org/enso/interpreter/runtime/data/Ref.java index b13742c2e2..069988b8a2 100644 --- a/engine/runtime/src/main/java/org/enso/interpreter/runtime/data/Ref.java +++ b/engine/runtime/src/main/java/org/enso/interpreter/runtime/data/Ref.java @@ -19,7 +19,7 @@ public final class Ref implements TruffleObject { * * @param value the initial value to store in the reference. */ - @Builtin.Method(description = "Creates a new Ref") + @Builtin.Method(description = "Creates a new Ref", autoRegister = false) public Ref(Object value) { this.value = value; } diff --git a/engine/runtime/src/main/java/org/enso/interpreter/runtime/data/Vector.java b/engine/runtime/src/main/java/org/enso/interpreter/runtime/data/Vector.java index 4b34f8e621..31dd62587f 100644 --- a/engine/runtime/src/main/java/org/enso/interpreter/runtime/data/Vector.java +++ b/engine/runtime/src/main/java/org/enso/interpreter/runtime/data/Vector.java @@ -37,8 +37,9 @@ public final class Vector implements TruffleObject { } @Builtin.Method( - name = "new_builtin", - description = "Creates new Vector with given length and provided elements.") + name = "new", + description = "Creates new Vector with given length and provided elements.", + autoRegister = false) @Builtin.Specialize public static Object newFromFunction(long length, Function fun, InteropLibrary interop) { Object[] target = new Object[Math.toIntExact(length)]; diff --git a/engine/runtime/src/main/java/org/enso/interpreter/runtime/error/Warning.java b/engine/runtime/src/main/java/org/enso/interpreter/runtime/error/Warning.java index 9b9b137a56..cc10f17393 100644 --- a/engine/runtime/src/main/java/org/enso/interpreter/runtime/error/Warning.java +++ b/engine/runtime/src/main/java/org/enso/interpreter/runtime/error/Warning.java @@ -53,7 +53,8 @@ public final class Warning implements TruffleObject { @Builtin.Method( name = "create", - description = "Creates a new instance of the primitive warning value.") + description = "Creates a new instance of the primitive warning value.", + autoRegister = false) @Builtin.Specialize public static Warning create(Context ctx, Object payload, Object origin) { return new Warning(payload, origin, ctx.clockTick()); @@ -67,7 +68,8 @@ public final class Warning implements TruffleObject { @Builtin.Method( name = "attach_with_stacktrace", - description = "Attaches the given warning to the value.") + description = "Attaches the given warning to the value.", + autoRegister = false) @Builtin.Specialize public static WithWarnings attach( Context ctx, WithWarnings value, Object warning, Object origin) { @@ -76,7 +78,8 @@ public final class Warning implements TruffleObject { @Builtin.Method( name = "attach_with_stacktrace", - description = "Attaches the given warning to the value.") + description = "Attaches the given warning to the value.", + autoRegister = false) @Builtin.Specialize(fallback = true) public static WithWarnings attach(Context ctx, Object value, Object warning, Object origin) { return new WithWarnings(value, new Warning(warning, origin, ctx.clockTick())); @@ -84,7 +87,8 @@ public final class Warning implements TruffleObject { @Builtin.Method( name = "get_all_array", - description = "Gets all the warnings associated with the value.") + description = "Gets all the warnings associated with the value.", + autoRegister = false) @Builtin.Specialize @CompilerDirectives.TruffleBoundary public static Array getAll(WithWarnings value) { @@ -97,7 +101,8 @@ public final class Warning implements TruffleObject { @Builtin.Method( name = "get_all_array", - description = "Gets all the warnings associated with the value.") + description = "Gets all the warnings associated with the value.", + autoRegister = false) @Builtin.Specialize(fallback = true) public static Array getAll(Object value) { return new Array(); @@ -105,7 +110,8 @@ public final class Warning implements TruffleObject { @Builtin.Method( name = "set_array", - description = "Gets all the warnings associated with the value.") + description = "Gets all the warnings associated with the value.", + autoRegister = false) @Builtin.Specialize public static Object set(WithWarnings value, Object warnings, InteropLibrary interop) { return setGeneric(value.getValue(), interop, warnings); @@ -113,7 +119,8 @@ public final class Warning implements TruffleObject { @Builtin.Method( name = "set_array", - description = "Gets all the warnings associated with the value.") + description = "Gets all the warnings associated with the value.", + autoRegister = false) @Builtin.Specialize(fallback = true) public static Object set(Object value, Object warnings, InteropLibrary interop) { return setGeneric(value, interop, warnings); diff --git a/engine/runtime/src/main/java/org/enso/interpreter/runtime/system/System.java b/engine/runtime/src/main/java/org/enso/interpreter/runtime/system/System.java index c8c2fb5518..bc65360003 100644 --- a/engine/runtime/src/main/java/org/enso/interpreter/runtime/system/System.java +++ b/engine/runtime/src/main/java/org/enso/interpreter/runtime/system/System.java @@ -22,7 +22,7 @@ public class System { private static final Text WINDOWS = Text.create("windows"); private static final Text UNKNOWN = Text.create("unknown"); - @Builtin.Method(description = "Get the type of operating system.") + @Builtin.Method(description = "Get the type of operating system.", autoRegister = false) @CompilerDirectives.TruffleBoundary public static Text os() { if (SystemUtils.IS_OS_LINUX) return LINUX; @@ -31,26 +31,30 @@ public class System { return UNKNOWN; } - @Builtin.Method(description = "Check if the operating system is UNIX.") + @Builtin.Method(description = "Check if the operating system is UNIX.", autoRegister = false) @CompilerDirectives.TruffleBoundary public static Boolean is_unix() { return SystemUtils.IS_OS_UNIX; } - @Builtin.Method(description = "Gets the nanosecond resolution system time.") + @Builtin.Method(description = "Gets the nanosecond resolution system time.", autoRegister = false) @CompilerDirectives.TruffleBoundary public static long nanoTime() { return java.lang.System.nanoTime(); } - @Builtin.Method(description = "Exits the process, returning the provided code.") + @Builtin.Method( + description = "Exits the process, returning the provided code.", + autoRegister = false) @CompilerDirectives.TruffleBoundary public static void exit(long code) { java.lang.System.exit((int) code); } @Builtin.Specialize - @Builtin.Method(description = "Create a system process, returning the exit code.") + @Builtin.Method( + description = "Create a system process, returning the exit code.", + autoRegister = false) @Builtin.WrapException(from = IOException.class, to = PanicException.class) @Builtin.WrapException(from = InterruptedException.class, to = PanicException.class) @CompilerDirectives.TruffleBoundary diff --git a/engine/runtime/src/main/scala/org/enso/compiler/codegen/IrToTruffle.scala b/engine/runtime/src/main/scala/org/enso/compiler/codegen/IrToTruffle.scala index dd3d2cf707..0063a7547a 100644 --- a/engine/runtime/src/main/scala/org/enso/compiler/codegen/IrToTruffle.scala +++ b/engine/runtime/src/main/scala/org/enso/compiler/codegen/IrToTruffle.scala @@ -331,8 +331,10 @@ class IrToTruffle( } consOpt.foreach { cons => + val fullMethodDefName = + cons.getName ++ Constants.SCOPE_SEPARATOR ++ methodDef.methodName.name val expressionProcessor = new ExpressionProcessor( - cons.getName ++ Constants.SCOPE_SEPARATOR ++ methodDef.methodName.name, + fullMethodDefName, scopeInfo.graph, scopeInfo.graph.rootScope, dataflowInfo @@ -375,7 +377,11 @@ class IrToTruffle( ) Right(None) else Left(l) ) - .map(_.filterNot(_ => cons.isBuiltin)) + .map(fOpt => + // Register builtin iff it has not been automatically registered at an early stage + // of builtins initialization. + fOpt.filter(m => !m.isAutoRegister()).map(m => m.getFunction) + ) case fn: IR.Function => val bodyBuilder = new expressionProcessor.BuildFunctionBody( diff --git a/engine/runtime/src/test/scala/org/enso/interpreter/test/semantic/PolyglotTest.scala b/engine/runtime/src/test/scala/org/enso/interpreter/test/semantic/PolyglotTest.scala index bb399b391d..6129b7caf4 100644 --- a/engine/runtime/src/test/scala/org/enso/interpreter/test/semantic/PolyglotTest.scala +++ b/engine/runtime/src/test/scala/org/enso/interpreter/test/semantic/PolyglotTest.scala @@ -16,6 +16,7 @@ class PolyglotTest extends InterpreterTest { "allow calling methods on static objects" in { val code = """from Standard.Base import all + |import Standard.Base.Data.Array | |main = | class = Java.lookup_class "org.enso.example.TestClass" @@ -60,6 +61,7 @@ class PolyglotTest extends InterpreterTest { "allow instantiating objects and calling methods on them" in { val code = """from Standard.Base import all + |import Standard.Base.Data.Array | |main = | class = Java.lookup_class "org.enso.example.TestClass" @@ -72,6 +74,7 @@ class PolyglotTest extends InterpreterTest { "allow listing available members of an object" in { val code = """from Standard.Base import all + |import Standard.Base.Data.Array | |main = | class = Java.lookup_class "org.enso.example.TestClass" @@ -106,7 +109,7 @@ class PolyglotTest extends InterpreterTest { consumeOut shouldEqual List("0", "[]") } - "match on Polyglot type when imported everything from stdlib" in { + "fail to match on Polyglot symbol when imported everything from stdlib" in { val code = """from Standard.Base import all |polyglot java import java.util.Random @@ -119,7 +122,7 @@ class PolyglotTest extends InterpreterTest { |""".stripMargin eval(code) val count :: Nil = consumeOut - count shouldEqual "OK" + count shouldEqual "FAIL" } "fail to match on Polyglot type when explicitly importing everything from Polyglot module" in { diff --git a/lib/scala/interpreter-dsl/src/main/java/org/enso/interpreter/dsl/Builtin.java b/lib/scala/interpreter-dsl/src/main/java/org/enso/interpreter/dsl/Builtin.java index 6a5a898ad9..3ec36b7962 100644 --- a/lib/scala/interpreter-dsl/src/main/java/org/enso/interpreter/dsl/Builtin.java +++ b/lib/scala/interpreter-dsl/src/main/java/org/enso/interpreter/dsl/Builtin.java @@ -153,6 +153,13 @@ public @interface Builtin { * @return number of desired expansions for vararg parameter. */ int expandVarargs() default 0; + + /** + * `autoRegister` property indicates whether the builtin method should be automatically + * registered with the underlying type. By default every builtin method is registered with a + * type. Auto-registered methods do not have to be declared explicitly. + */ + boolean autoRegister() default true; } /** diff --git a/lib/scala/interpreter-dsl/src/main/java/org/enso/interpreter/dsl/BuiltinMethod.java b/lib/scala/interpreter-dsl/src/main/java/org/enso/interpreter/dsl/BuiltinMethod.java index fa9d76742a..cf071ca70c 100644 --- a/lib/scala/interpreter-dsl/src/main/java/org/enso/interpreter/dsl/BuiltinMethod.java +++ b/lib/scala/interpreter-dsl/src/main/java/org/enso/interpreter/dsl/BuiltinMethod.java @@ -20,4 +20,7 @@ public @interface BuiltinMethod { /** @return a list of aliases (names) of this method */ String aliases() default ""; + + /** @return whether a method should be registered automatically with a type */ + boolean autoRegister() default true; } diff --git a/lib/scala/interpreter-dsl/src/main/java/org/enso/interpreter/dsl/BuiltinsMetadataProcessor.java b/lib/scala/interpreter-dsl/src/main/java/org/enso/interpreter/dsl/BuiltinsMetadataProcessor.java index d28daecd98..e5df23f8a7 100644 --- a/lib/scala/interpreter-dsl/src/main/java/org/enso/interpreter/dsl/BuiltinsMetadataProcessor.java +++ b/lib/scala/interpreter-dsl/src/main/java/org/enso/interpreter/dsl/BuiltinsMetadataProcessor.java @@ -97,7 +97,7 @@ public abstract class BuiltinsMetadataProcessor { - private final Map> builtinMethods = new HashMap<>(); + private final Map> builtinMethods = new HashMap<>(); /** * Processes annotated elements, generating code for each of them. The method also records @@ -108,10 +109,10 @@ public class MethodProcessor extends BuiltinsMetadataProcessor pastEntries) throws IOException { for (Filer f : builtinMethods.keySet()) { - for (Map.Entry entry : builtinMethods.get(f).entrySet()) { - writer.append(entry.getKey() + ":" + entry.getValue() + "\n"); + for (Map.Entry entry : builtinMethods.get(f).entrySet()) { + writer.append(entry.getKey() + ":" + String.join(":", Arrays.asList(entry.getValue())) + "\n"); if (pastEntries.containsKey(entry.getKey())) { pastEntries.remove(entry.getKey()); } @@ -472,13 +473,13 @@ public class MethodProcessor extends BuiltinsMetadataProcessor methods = builtinMethods.get(f); + protected void registerBuiltinMethod(Filer f, String name, String clazzName, boolean isStatic, boolean isAutoRegister) { + Map methods = builtinMethods.get(f); if (methods == null) { methods = new HashMap<>(); builtinMethods.put(f, methods); } - methods.put(name, clazzName); + methods.put(name, new String[] { clazzName, String.valueOf(isStatic), String.valueOf(isAutoRegister) }); } @Override @@ -511,11 +512,11 @@ public class MethodProcessor extends BuiltinsMetadataProcessor arg.isSelf()) + .findFirst() + .map(arg -> arg.isSyntheticSelf()) + .orElseGet(() -> false); + } + + public boolean isAutoRegister() { + return annotation.autoRegister(); + } + public interface ArgumentDefinition { boolean validate(ProcessingEnvironment processingEnvironment); @@ -242,6 +253,8 @@ public class MethodDefinition { boolean isSelf(); + boolean isSyntheticSelf(); + boolean shouldCheckErrors(); boolean shouldCheckWarnings(); @@ -332,6 +345,11 @@ public class MethodDefinition { return true; } + @Override + public boolean isSyntheticSelf() { + return true; + } + @Override public boolean shouldCheckErrors() { return false; @@ -518,6 +536,11 @@ public class MethodDefinition { return name.equals(SELF); } + @Override + public boolean isSyntheticSelf() { + return false; + } + public boolean shouldCheckErrors() { return isPositional() && !isSelf() && !acceptsError(); } diff --git a/test/Tests/src/Data/Array_Spec.enso b/test/Tests/src/Data/Array_Spec.enso index 49b94447a7..b63f6e1ae0 100644 --- a/test/Tests/src/Data/Array_Spec.enso +++ b/test/Tests/src/Data/Array_Spec.enso @@ -1,10 +1,11 @@ from Standard.Base import all +import Standard.Base.Data.Array from Standard.Test import Test, Test_Suite polyglot java import java.util.LinkedHashSet -Array.method self = 0 +Array.Array.method self = 0 ## Returns an array with the same contents as the given vector, surely backed by the Enso Array primitive. diff --git a/test/Tests/src/Data/Time/Date_Spec.enso b/test/Tests/src/Data/Time/Date_Spec.enso index 78fd16cf23..534e894fb9 100644 --- a/test/Tests/src/Data/Time/Date_Spec.enso +++ b/test/Tests/src/Data/Time/Date_Spec.enso @@ -427,7 +427,7 @@ js_set_zone local_datetime = zone = Time_Zone.utc datetime_with_tz = local_datetime.at_zone zone diff = Duration.between datetime_with_tz local_datetime (timezone_aware=False) - (datetime_with_tz + diff).to_localdate_builtin + (datetime_with_tz + diff).date js_date year month=1 day=1 = Panic.catch Any (js_set_zone (js_date_impl year month day)) (err -> Error.throw (Time_Error_Data err.payload.cause)) diff --git a/test/Tests/src/Semantic/Case_Spec.enso b/test/Tests/src/Semantic/Case_Spec.enso index 5a9c7440e7..b4a422715f 100644 --- a/test/Tests/src/Semantic/Case_Spec.enso +++ b/test/Tests/src/Semantic/Case_Spec.enso @@ -101,10 +101,10 @@ spec = Test.group "Pattern Matches" <| Test.specify "should be able to match on the Polyglot type" <| random_gen = Random.new case random_gen of - Polyglot -> Nothing + Polyglot.Polyglot -> Nothing _ -> Test.fail "Expected a polyglot object to match." - case Polyglot of - Polyglot -> Nothing + case Polyglot.Polyglot of + Polyglot.Polyglot -> Nothing _ -> Test.fail "Expected the Polyglot constructor to match." Test.specify "should be able to match on the Any type" <| value_1 = 1.23143 diff --git a/test/Tests/src/Semantic/Meta_Spec.enso b/test/Tests/src/Semantic/Meta_Spec.enso index 411fb456b9..68f37c1712 100644 --- a/test/Tests/src/Semantic/Meta_Spec.enso +++ b/test/Tests/src/Semantic/Meta_Spec.enso @@ -79,7 +79,7 @@ spec = Test.group "Meta-Value Manipulation" <| 1.0.is_a Text . should_be_false random_gen = Random.new - Meta.is_a random_gen Polyglot . should_be_true + Meta.is_a random_gen Polyglot.Polyglot . should_be_true Meta.is_a random_gen Integer . should_be_false (My_Type.Value 1 "foo" Nothing).is_a My_Type.Value . should_be_true diff --git a/test/micro-distribution/lib/Standard/Base/0.0.0-dev/src/Data/Any.enso b/test/micro-distribution/lib/Standard/Base/0.0.0-dev/src/Data/Any.enso index 5b0f4405ab..ad1a79197e 100644 --- a/test/micro-distribution/lib/Standard/Base/0.0.0-dev/src/Data/Any.enso +++ b/test/micro-distribution/lib/Standard/Base/0.0.0-dev/src/Data/Any.enso @@ -1,2 +1,5 @@ @Builtin_Type type Any + catch_primitive handler = @Builtin_Method "Any.catch_primitive" + to_text self = @Builtin_Method "Any.to_text" + to_display_text self = @Builtin_Method "Any.to_display_text" diff --git a/test/micro-distribution/lib/Standard/Base/0.0.0-dev/src/Data/Array.enso b/test/micro-distribution/lib/Standard/Base/0.0.0-dev/src/Data/Array.enso index 0b85d9cffc..3dcbecfeda 100644 --- a/test/micro-distribution/lib/Standard/Base/0.0.0-dev/src/Data/Array.enso +++ b/test/micro-distribution/lib/Standard/Base/0.0.0-dev/src/Data/Array.enso @@ -1,5 +1,7 @@ @Builtin_Type type Array + at self index = @Builtin_Method "Array.at" + length self = @Builtin_Method "Array.length" new_1 item_1 = @Builtin_Method "Array.new_1" new_2 item_1 item_2 = @Builtin_Method "Array.new_2" diff --git a/test/micro-distribution/lib/Standard/Base/0.0.0-dev/src/Data/Boolean.enso b/test/micro-distribution/lib/Standard/Base/0.0.0-dev/src/Data/Boolean.enso index 17fec8a94b..bcd114d92f 100644 --- a/test/micro-distribution/lib/Standard/Base/0.0.0-dev/src/Data/Boolean.enso +++ b/test/micro-distribution/lib/Standard/Base/0.0.0-dev/src/Data/Boolean.enso @@ -6,3 +6,6 @@ type Boolean True False if_then_else self ~on_true ~on_false = @Builtin_Method "Boolean.if_then_else" + && self ~that = @Builtin_Method "Boolean.&&" + || self ~that = @Builtin_Method "Boolean.||" + not self = @Builtin_Method "Boolean.not" diff --git a/test/micro-distribution/lib/Standard/Base/0.0.0-dev/src/Data/Text.enso b/test/micro-distribution/lib/Standard/Base/0.0.0-dev/src/Data/Text.enso index 98c9e6791f..3130121e53 100644 --- a/test/micro-distribution/lib/Standard/Base/0.0.0-dev/src/Data/Text.enso +++ b/test/micro-distribution/lib/Standard/Base/0.0.0-dev/src/Data/Text.enso @@ -1,2 +1,3 @@ @Builtin_Type type Text + + self that = @Builtin_Method "Text.+" diff --git a/test/micro-distribution/lib/Standard/Base/0.0.0-dev/src/Data/Time/Time_Zone.enso b/test/micro-distribution/lib/Standard/Base/0.0.0-dev/src/Data/Time/Time_Zone.enso index 94024dbe5b..4a0ce5ae90 100644 --- a/test/micro-distribution/lib/Standard/Base/0.0.0-dev/src/Data/Time/Time_Zone.enso +++ b/test/micro-distribution/lib/Standard/Base/0.0.0-dev/src/Data/Time/Time_Zone.enso @@ -2,4 +2,6 @@ type Time_Zone new (hours = 0) (minutes = 0) (seconds = 0) = - Time_Zone.new_builtin hours minutes seconds + new_builtin hours minutes seconds + +new_builtin hours minutes seconds = @Builtin_Method "Time_Zone.new_builtin" diff --git a/test/micro-distribution/lib/Standard/Base/0.0.0-dev/src/Main.enso b/test/micro-distribution/lib/Standard/Base/0.0.0-dev/src/Main.enso index daa2cd183c..09ca31dea5 100644 --- a/test/micro-distribution/lib/Standard/Base/0.0.0-dev/src/Main.enso +++ b/test/micro-distribution/lib/Standard/Base/0.0.0-dev/src/Main.enso @@ -20,10 +20,10 @@ import project.Data.Numbers from project.Data.Numbers export Number import project.Data.Vector -from project.Data.Vector export Vector +export project.Data.Vector import project.Polyglot -from project.Polyglot export all +export project.Polyglot import project.Polyglot.Java export project.Polyglot.Java diff --git a/test/micro-distribution/lib/Standard/Base/0.0.0-dev/src/Polyglot.enso b/test/micro-distribution/lib/Standard/Base/0.0.0-dev/src/Polyglot.enso index c7be2a4722..c902a565b6 100644 --- a/test/micro-distribution/lib/Standard/Base/0.0.0-dev/src/Polyglot.enso +++ b/test/micro-distribution/lib/Standard/Base/0.0.0-dev/src/Polyglot.enso @@ -1,5 +1,6 @@ @Builtin_Type type Polyglot + get_array_size array = @Builtin_Method "Polyglot.get_array_size" execute callable arguments = @Builtin_Method "Polyglot.execute" get_member object member_name = @Builtin_Method "Polyglot.get_member"