-
-
Notifications
You must be signed in to change notification settings - Fork 5.5k
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
Julep/Very WIP - Heap allocated immutable arrays and compiler support #31630
Closed
Closed
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -916,6 +916,10 @@ export | |
rand, | ||
randn, | ||
|
||
# mutation | ||
freeze, | ||
melt, | ||
|
||
# Macros | ||
# parser internal | ||
@__FILE__, | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -1014,7 +1014,9 @@ JL_CALLABLE(jl_f__typevar) | |
JL_CALLABLE(jl_f_arraysize) | ||
{ | ||
JL_NARGS(arraysize, 2, 2); | ||
JL_TYPECHK(arraysize, array, args[0]); | ||
if (!jl_is_arrayish(args[0])) { | ||
jl_type_error("arraysize", (jl_value_t*)jl_array_type, args[0]); | ||
} | ||
jl_array_t *a = (jl_array_t*)args[0]; | ||
size_t nd = jl_array_ndims(a); | ||
JL_TYPECHK(arraysize, long, args[1]); | ||
|
@@ -1053,7 +1055,9 @@ JL_CALLABLE(jl_f_arrayref) | |
{ | ||
JL_NARGSV(arrayref, 3); | ||
JL_TYPECHK(arrayref, bool, args[0]); | ||
JL_TYPECHK(arrayref, array, args[1]); | ||
if (!jl_is_arrayish(args[1])) { | ||
jl_type_error("arrayref", (jl_value_t*)jl_array_type, args[1]); | ||
} | ||
jl_array_t *a = (jl_array_t*)args[1]; | ||
size_t i = array_nd_index(a, &args[2], nargs - 2, "arrayref"); | ||
return jl_arrayref(a, i); | ||
|
@@ -1075,6 +1079,49 @@ JL_CALLABLE(jl_f_arrayset) | |
return args[1]; | ||
} | ||
|
||
JL_CALLABLE(jl_f_arrayfreeze) | ||
{ | ||
JL_NARGSV(arrayfreeze, 1); | ||
JL_TYPECHK(arrayfreeze, array, args[0]); | ||
jl_array_t *a = (jl_array_t*)args[0]; | ||
jl_datatype_t *it = (jl_datatype_t *)jl_apply_type2((jl_value_t*)jl_immutable_array_type, | ||
jl_tparam0(jl_typeof(a)), jl_tparam1(jl_typeof(a))); | ||
// The idea is to elide this copy if the compiler or runtime can prove that | ||
// doing so is safe to do. | ||
jl_array_t *na = jl_array_copy(a); | ||
jl_set_typeof(na, it); | ||
return (jl_value_t*)na; | ||
} | ||
|
||
JL_CALLABLE(jl_f_mutating_arrayfreeze) | ||
{ | ||
JL_NARGSV(arrayfreeze, 1); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
|
||
JL_TYPECHK(arrayfreeze, array, args[0]); | ||
jl_array_t *a = (jl_array_t*)args[0]; | ||
jl_datatype_t *it = (jl_datatype_t *)jl_apply_type2((jl_value_t*)jl_immutable_array_type, | ||
jl_tparam0(jl_typeof(a)), jl_tparam1(jl_typeof(a))); | ||
// The idea is to elide this copy if the compiler or runtime can prove that | ||
// doing so is safe to do. | ||
jl_set_typeof(a, it); | ||
return (jl_value_t*)a; | ||
} | ||
|
||
JL_CALLABLE(jl_f_arraymelt) | ||
{ | ||
JL_NARGSV(arrayfreeze, 1); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
|
||
if (((jl_datatype_t*)jl_typeof(args[0]))->name != jl_immutable_array_typename) { | ||
jl_type_error("arraymelt", (jl_value_t*)jl_immutable_array_type, args[0]); | ||
} | ||
jl_array_t *a = (jl_array_t*)args[0]; | ||
jl_datatype_t *it = (jl_datatype_t *)jl_apply_type2((jl_value_t*)jl_array_type, | ||
jl_tparam0(jl_typeof(a)), jl_tparam1(jl_typeof(a))); | ||
// The idea is to elide this copy if the compiler or runtime can prove that | ||
// doing so is safe to do. | ||
jl_array_t *na = jl_array_copy(a); | ||
jl_set_typeof(na, it); | ||
return (jl_value_t*)na; | ||
} | ||
|
||
// IntrinsicFunctions --------------------------------------------------------- | ||
|
||
static void (*runtime_fp[num_intrinsics])(void); | ||
|
@@ -1218,6 +1265,9 @@ void jl_init_primitives(void) JL_GC_DISABLED | |
add_builtin_func("const_arrayref", jl_f_arrayref); | ||
add_builtin_func("arrayset", jl_f_arrayset); | ||
add_builtin_func("arraysize", jl_f_arraysize); | ||
add_builtin_func("arrayfreeze", jl_f_arrayfreeze); | ||
add_builtin_func("mutating_arrayfreeze", jl_f_mutating_arrayfreeze); | ||
add_builtin_func("arraymelt", jl_f_arraymelt); | ||
|
||
// method table utils | ||
add_builtin_func("applicable", jl_f_applicable); | ||
|
@@ -1276,6 +1326,7 @@ void jl_init_primitives(void) JL_GC_DISABLED | |
add_builtin("AbstractArray", (jl_value_t*)jl_abstractarray_type); | ||
add_builtin("DenseArray", (jl_value_t*)jl_densearray_type); | ||
add_builtin("Array", (jl_value_t*)jl_array_type); | ||
add_builtin("ImmutableArray", (jl_value_t*)jl_immutable_array_type); | ||
|
||
add_builtin("Expr", (jl_value_t*)jl_expr_type); | ||
add_builtin("LineNumberNode", (jl_value_t*)jl_linenumbernode_type); | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
At first, I was thrown by what this name meant. It makes sense in the end; in this case you are sort-of mutating the type of
a
but not the value/data... though I did wonder if it would be better language to describe this as "taking" or "stealing"a
or something like that.