Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Move Builtin Types and Methods to stdlib #3363

Merged
merged 80 commits into from
May 5, 2022
Merged
Show file tree
Hide file tree
Changes from 4 commits
Commits
Show all changes
80 commits
Select commit Hold shift + click to select a range
38a2da7
Dynamically replace builtin methods with functions
hubertp Mar 25, 2022
374a94c
Deal with Polyglot split by selectively importing
hubertp Mar 29, 2022
6afa443
Move Array type out of Builtins
hubertp Apr 4, 2022
02ab5b1
Move Ref type + basic test
hubertp Apr 4, 2022
6938b2d
Move Boolean out of Builtins to std library
hubertp Apr 5, 2022
75cd43d
Drop reflection requirement for builtin methods
hubertp Apr 6, 2022
0f89f44
Use constant values to avoid typos
hubertp Apr 6, 2022
91c6432
Move Meta out of builtins
hubertp Apr 7, 2022
43840f2
Revert "Move Boolean out of Builtins to std library"
hubertp Apr 8, 2022
9822d76
wip
hubertp Apr 9, 2022
e561565
Move Any to stdlib
hubertp Apr 11, 2022
9dbfa06
Move Boolean to stdlib
hubertp Apr 11, 2022
c42b092
Missing Booleans.enso from last commit
hubertp Apr 11, 2022
fb10830
Simplify builtins metadata generation
hubertp Apr 11, 2022
fb666c1
Cleanup
hubertp Apr 12, 2022
1dc9594
Simplify resource reading
hubertp Apr 12, 2022
8ca36e8
Merge branch 'develop' into wip/hubert/shadow-definition-builtins-181…
hubertp Apr 12, 2022
a588c80
Move List to stdlib
hubertp Apr 12, 2022
d771a7f
WIP: remove hardcoded builtin types in Builtins
hubertp Apr 13, 2022
d529ad8
Workaround separate compilation problems
hubertp Apr 13, 2022
3cfdedd
Address PR review
hubertp Apr 14, 2022
8ee6654
CamelCase to Snake_Case for builtin types
hubertp Apr 14, 2022
c04f11e
Move DataflowError to stdlib
hubertp Apr 15, 2022
20f8be4
typo
hubertp Apr 15, 2022
fd094e1
Move all error types + text
hubertp Apr 19, 2022
1a2a80a
Move IO stuff
hubertp Apr 19, 2022
8e76ba8
Add missing shared test class
hubertp Apr 19, 2022
d261608
Improve runtime of tests
hubertp Apr 19, 2022
d3e5fa8
Add IO to stdlib
hubertp Apr 19, 2022
75ba97c
DRY
hubertp Apr 19, 2022
870aacd
nit
hubertp Apr 19, 2022
67dafaa
Final AtomConstructor
hubertp Apr 19, 2022
f75be8a
Move Nothing and Function to stdlib
hubertp Apr 20, 2022
f0b45a7
Nits
hubertp Apr 21, 2022
8e7e15f
Cons/Nil are no longer Builtin_Types
hubertp Apr 21, 2022
b6ae3f0
Adapt benchmark fixtures
hubertp Apr 21, 2022
870ef1a
Remove unused imports
hubertp Apr 21, 2022
70d558d
Rename local 'reverse' method in List benchmarks
hubertp Apr 21, 2022
4f1fe32
Amend benchmark with missing import
hubertp Apr 21, 2022
6cfeca0
Make benchmarks happy again
hubertp Apr 21, 2022
b6fe9cc
fix typo
hubertp Apr 21, 2022
f17d3cb
Move runtime builtin types to stdlib
hubertp Apr 22, 2022
e4037b4
Move Prim_Warning to stdlib
hubertp Apr 22, 2022
1a586d9
Builtins is dead, long live builtins
hubertp Apr 25, 2022
da040f8
Missed some test adaptation
hubertp Apr 25, 2022
4e4535e
Getting rid of Standard.Builtins mentions
hubertp Apr 25, 2022
10d1a52
Remove empty Builtins.enso references
hubertp Apr 25, 2022
5ae3289
Automatic formatting
hubertp Apr 25, 2022
69ad669
Remove extension method for unimplemented error
hubertp Apr 25, 2022
966c2f1
Merge branch 'develop' into wip/hubert/shadow-definition-builtins-181…
hubertp Apr 25, 2022
1372387
Minor adjustments to expectations
hubertp Apr 25, 2022
9a703a3
Update Changelog
hubertp Apr 25, 2022
2ddcf9f
More docs for annotation processors
hubertp Apr 25, 2022
c927582
More Standard.Builtins purge
hubertp Apr 25, 2022
f7145e8
Merge branch 'develop' into wip/hubert/shadow-definition-builtins-181…
hubertp Apr 28, 2022
1ecd317
Follow up on merge with develop
hubertp Apr 28, 2022
a384ed0
PR review re IO and Prim_Io modules
hubertp Apr 28, 2022
40ad2c7
PR review Numbers
hubertp Apr 28, 2022
23e9298
Remove builtin Ordering type
hubertp Apr 28, 2022
a33b45d
Move FIXME comment on Ref to pivotal ticket
hubertp Apr 28, 2022
0c5c19c
Remove leftover comment
hubertp Apr 28, 2022
3417b66
More cleanups, as per PR comments
hubertp Apr 28, 2022
7dc9a34
Formatting
hubertp Apr 28, 2022
3adc0ef
Remove logic to handle Any/Nothing methods
hubertp Apr 29, 2022
dc11b5a
Auto-generate Builtins Constants
hubertp Apr 29, 2022
9414fce
Test adjustments to the previous commit
hubertp May 4, 2022
fa4ca5b
Update distribution/lib/Standard/Base/0.0.0-dev/src/Error/Common.enso
hubertp May 4, 2022
cba36f3
Make formatter happy again
hubertp May 4, 2022
7bf6261
DRY
hubertp May 4, 2022
fe89bc1
Add a requested compiler assert
hubertp May 4, 2022
1c40d25
Merge branch 'develop' into wip/hubert/shadow-definition-builtins-181…
hubertp May 4, 2022
6ba1bc4
Fix tests
hubertp May 4, 2022
4fde6ba
Increase timeout to avoid FPs
hubertp May 4, 2022
b10bb8c
Turn on IR caches for tests
hubertp May 5, 2022
6f27d5e
Merge branch 'develop' into wip/hubert/shadow-definition-builtins-181…
hubertp May 5, 2022
aeeef17
Fix tests
hubertp May 5, 2022
670cad6
Merge branch 'develop' into wip/hubert/shadow-definition-builtins-181…
hubertp May 5, 2022
6c06032
Make disabling IR cache in tests configurable
hubertp May 5, 2022
c90836d
More formatting
hubertp May 5, 2022
884a7d1
Merge branch 'develop' into wip/hubert/shadow-definition-builtins-181…
hubertp May 5, 2022
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
x ->
result = Builtins.Ref.new '{ message: ""}'
result = Ref.new '{ message: ""}'
x.catch err->
message = err.to_display_text
Builtins.Ref.put result ('{ "kind": "Dataflow", "message": ' + message.to_json.to_text + '}')
Builtins.Ref.get result
Ref.put result ('{ "kind": "Dataflow", "message": ' + message.to_json.to_text + '}')
Ref.get result

3 changes: 2 additions & 1 deletion build.sbt
Original file line number Diff line number Diff line change
Expand Up @@ -1147,7 +1147,8 @@ lazy val runtime = (project in file("engine/runtime"))
"org.scalatest" %% "scalatest" % scalatestVersion % Test,
"org.graalvm.truffle" % "truffle-api" % graalVersion % Benchmark,
"org.typelevel" %% "cats-core" % catsVersion,
"eu.timepit" %% "refined" % refinedVersion
"eu.timepit" %% "refined" % refinedVersion,
"org.reflections" % "reflections" % "0.10.2"
hubertp marked this conversation as resolved.
Show resolved Hide resolved
),
// Note [Unmanaged Classpath]
Compile / unmanagedClasspath += (`core-definition` / Compile / packageBin).value,
Expand Down
179 changes: 179 additions & 0 deletions distribution/lib/Standard/Base/0.0.0-dev/src/Data/Array.enso
Original file line number Diff line number Diff line change
@@ -0,0 +1,179 @@
import Standard.Base.Data.Vector

## Utilities for working with primitive arrays.
type Array

## The type of primitive mutable arrays.
@Builtin_Type
type Array

## Gets the element at index in the array this.

Arguments:
- index: The index to get the element from.

? Safety
If index < 0 or index >= this.length, then this operation will result
in an Invalid_Array_Index_Error exception.

> Example
Get the element at index 1.

[1,2,3].to_array.at 1
at : Integer -> Any
at index = @Builtin_Method "Array.at"

## Set the cell at the specified index to the provided value, returning
the array.

Arguments:
- index: The position in the array to set.
- value: The value to set at position index.

The array is mutated in place, and only returned to facilitate a natural
programming style in Enso.

? Safety
If index < 0 or index >= this.length, then this operation will result
in an Invalid_Array_Index_Error exception.
set_at : Integer -> Any -> Array
set_at index value = @Builtin_Method "Array.set_at"

## Gets the length of the array this.

> Example
Getting the length of an array.

[1,2,3].to_array.length
length : Integer
length = @Builtin_Method "Array.length"

## Sorts the this array in place.

Arguments:
- comparator: A comparison function that takes two elements and returns
an Ordering that describes how the first element is ordered with
respect to the second.

> Example
Sorting an array of numbers.

[1,2,3].to_array.sort
sort : (Any -> Any -> Ordering) -> Nothing
sort comparator = @Builtin_Method "Array.sort"

## Identity.

This method is implemented purely for completeness with the runtime's
primitive array protocol.
to_array : Array
to_array = @Builtin_Method "Array.to_array"

## UNSTABLE
ADVANCED

Returns a Text used to display this value in the IDE.

The particular representation is left unspecified and subject to change in
the future. The current implementation uses JSON serialization as the
default.

> Example
Converting an array to its default visualization representation.

[1, 2, 3, 4].to_array.to_default_visualization_data
to_default_visualization_data : Text
to_default_visualization_data =
Vector.Vector this . to_default_visualization_data

## Creates an array with length 0.

> Example
Create an empty array.

Array.empty
empty : Array
empty = @Builtin_Method "Array.empty"

## Creates a new array of length size, with all elements uninitialized.

Arguments:
- size: The size of the array to create.

> Example
Create a new array of size 10.

Array.new 10
new : Integer -> Array
new size = @Builtin_Method "Array.new"

## PRIVATE

Create an array with one element provided.

Arguments:
- item_1: The one element in the array.
new_1 : Any -> Array
new_1 item_1 = @Builtin_Method "Array.new_1"

## PRIVATE

Create an array with two elements provided.

Arguments:
- item_1: The first element.
- item_2: The second element.
new_2 : Any -> Any -> Array
new_2 item_1 item_2 = @Builtin_Method "Array.new_2"

## PRIVATE

Create an array with three elements provided.

Arguments:
- item_1: The first element.
- item_2: The second element.
- item_3: The third element.
new_3 : Any -> Any -> Any -> Array
new_3 item_1 item_2 item_3 = @Builtin_Method "Array.new_3"

## PRIVATE

Create an array with four elements provided.

Arguments:
- item_1: The first element.
- item_2: The second element.
- item_3: The third element.
- item_4: The fourth element.
new_4 : Any -> Any -> Any -> Any -> Array
new_4 item_1 item_2 item_3 item_4 = @Builtin_Method "Array.new_4"

## Copies from the source array, beginning at the specified position, to the
specified position in the destination array.

Arguments:
- src: The source array.
- source_index: The start position in the src array.
- dest: The desination array.
- dest_index: The start position in the that array.

A subsequence of array elements are copied from the src array to the
dest array. The number of components copied is equal to count. The
components at positions source_index through source_index + count - 1
in the strc array are copied into positions dest_index through
dest_index + count - 1, respectively, of the destination array.

If the src and dest arguments refer to the same array, then the copy
is performed as if the components at positions source_index through
source_index + count - 1 are first copied to a temporary array with
length count, and then the contents of the temporary array are copied
into positions dest_index through dest_index + count - 1 of the
destination array.

> Example
Copying elements from one array to another.

Array.copy [1,2,3].to_array 0 (Vector.fill 3 0).to_array 0 3
copy : Array -> Integer -> Array -> Integer -> Integer -> Nothing
copy src source_index dest dest_index count = @Builtin_Method "Array.copy"

This file was deleted.

45 changes: 45 additions & 0 deletions distribution/lib/Standard/Base/0.0.0-dev/src/Data/Ref.enso
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
## Utilities for working with mutable references.
type Ref

## A mutable reference type.
@Builtin_Type
type Ref

## FIXME consider moving this as methods of Ref, currently a lot of stuff depends
## on the current design
hubertp marked this conversation as resolved.
Show resolved Hide resolved
## Gets the contents of the mutable reference ref.

Arguments:
- ref: The reference to get the contents of.

> Example
Getting the contents of a reference.

Ref.get (Ref.new 0)
get : Ref -> Any
get ref = @Builtin_Method "Ref.get"

## Puts a new value into the reference, returning the old value.

Arguments:
- ref: The reference in which to store the value.
- new_value: The new value to store in ref.

> Example
Storing the value 10 in a reference.

Ref.put (Ref.new 0) 10
put : Ref -> Any -> Any
put ref new_value = @Builtin_Method "Ref.put"

## Creates a new reference containing the provided value.

Arguments:
- value: The value to be contained in the ref.

> Example
Creating a new reference containing the value 7.

Ref.new 7
new : Any -> Ref
new value = @Builtin_Method "Ref.new"
Original file line number Diff line number Diff line change
Expand Up @@ -39,11 +39,9 @@ import Standard.Base.Data.Text.Regex
import Standard.Base.Data.Text.Regex.Engine
import Standard.Base.Data.Text.Regex.Option as Global_Option
import Standard.Base.Data.Text.Regex.Mode
import Standard.Base.Polyglot.Java as Java_Ext
import Standard.Base.Polyglot.Java
from Standard.Base.Data.Text.Span as Span_Module import Utf_16_Span

from Standard.Builtins import Java

import Standard.Base.Error.Extensions as Errors

polyglot java import java.lang.IllegalArgumentException
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
from Standard.Base import all
from Standard.Builtins import Array
from Standard.Builtins import Unsupported_Argument_Types

## Creates a new vector of the given length, initializing elements using
Expand Down
11 changes: 7 additions & 4 deletions distribution/lib/Standard/Base/0.0.0-dev/src/Main.enso
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import project.Data.Any.Extensions
import project.Data.Array.Extensions
import project.Data.Array
import project.Data.Interval
import project.Data.Json
import project.Data.List
Expand All @@ -12,6 +12,7 @@ import project.Data.Ordering
import project.Data.Ordering.Sort_Order
import project.Data.Pair
import project.Data.Range
import project.Data.Ref
import project.Data.Text.Extensions
import project.Data.Text.Matching
import project.Data.Vector
Expand All @@ -20,6 +21,7 @@ import project.Error.Extensions
import project.Math
import project.Meta
import project.Meta.Enso_Project
import project.Polyglot
import project.Polyglot.Java
import project.Runtime.Extensions
import project.System.Environment
Expand All @@ -39,18 +41,20 @@ export project.Data.Ordering.Sort_Order
export project.Data.Vector
export project.Math
export project.Meta
export project.Polyglot.Java
export project.System.Environment
export project.System.File
export project.Data.Text.Regex.Mode as Regex_Mode
export project.Warning

from project.Data.Array export Array
from project.Data.Any.Extensions export all
from project.Data.Array.Extensions export all
from project.Data.List export Nil, Cons
from project.Data.Number.Extensions export all hiding Math, String, Double
from project.Data.Noise export all hiding Noise
from project.Data.Pair export Pair
from project.Data.Range export Range
from project.Data.Ref export Ref
## TODO [RW] Once autoscoping is implemented or automatic imports for ADTs are
fixed in the IDE, we should revisit if we want to export ADTs like `Case` by
default. It may be unnecessary pollution of scope, but until the issues are
Expand All @@ -63,8 +67,7 @@ from project.Data.Text.Matching export Case_Insensitive, Text_Matcher, Regex_Mat
from project.Error.Common export all
from project.Error.Extensions export all
from project.Meta.Enso_Project export all
from project.Polyglot.Java export all
from project.Polyglot export all
from project.Runtime.Extensions export all

from Standard.Builtins export all hiding Meta, Less, Equal, Greater, Ordering

Loading