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

Add partially evaluated methods ===(x), !==(x), and isa(T) #36759

Closed
wants to merge 8 commits into from

Conversation

tkf
Copy link
Member

@tkf tkf commented Jul 22, 2020

This PR adds ===(x), !==(x), and isa(T) that creates a Fix2 like isequal etc. For ===(x) and isa(T), it looks like I needed to add tfuncs.

fix #36163
fix #32018

@tkf tkf requested a review from JeffBezanson July 22, 2020 01:13
#else
#define DECLARE_BUILTIN(name) \
JL_CALLABLE(jl_f_##name); \
extern jl_value_t *jl_builtin_##name
extern jl_value_t *jl_builtin_##name JL_GLOBALLY_ROOTED
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is a bit of a long shot for working around analyzegc https://build.julialang.org/#/builders/65/builds/1574/steps/4/logs/stdio

But I wonder if there is a reason why this is not used? Maybe I'm doing something stupid here?

If this is not the right way to do it, maybe I need to do something like this?

diff --git a/src/builtins.c b/src/builtins.c
index 440b69629e..c2576d553d 100644
--- a/src/builtins.c
+++ b/src/builtins.c
@@ -369,6 +369,7 @@ JL_CALLABLE(jl_f_is)
         jl_function_t *fix2 = jl_get_function(jl_base_module, "Fix2");
         if (fix2 == NULL)
             jl_undefined_var_error(jl_symbol("Fix2"));
+        JL_GC_PROMISE_ROOTED(jl_builtin_is);
         return jl_call2(fix2, jl_builtin_is, args[0]);
     }
     if (args[0] == args[1])
@@ -440,6 +441,7 @@ JL_CALLABLE(jl_f_isa)
         jl_function_t *fix2 = jl_get_function(jl_base_module, "Fix2");
         if (fix2 == NULL)
             jl_undefined_var_error(jl_symbol("Fix2"));
+        JL_GC_PROMISE_ROOTED(jl_builtin_isa);
         return jl_call2(fix2, jl_builtin_isa, args[0]);
     }
     JL_TYPECHK(isa, type, args[1]);

===(x)

Create a function that compares its argument to `x` using [`===`](@ref), i.e.
a function equivalent to `y -> y == x`.
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should be y -> y === x

@JeffBezanson
Copy link
Member

This is tricky. I suspect the only good way to do this is to make === generic (also isa), since otherwise it will need special inlining and/or codegen support. What I would try is

  • Rename the current builtin === to something else
  • Move Fix2 to Core (boot.jl) and define the two methods of === there
  • Add a check to prevent adding more methods to ===
  • Inference can still handle Core.:(===) specially, since we know what it does
  • We might need to still make === a Builtin by special arrangement?
  • Check the impact on the compiler. Might need to e.g. avoid adding backedges to === (that would be a natural part of a general "sealed functions" feature).

@vtjnash
Copy link
Member

vtjnash commented Jul 22, 2020

Add a check to prevent adding more methods to ===

julia> setfield!(typeof(+).name.mt, fieldcount(Core.MethodTable), 0x01)
# this "seals" a method, and can trick it into thinking that `+` is now a subtype of `Core.Builtin`

julia> Base.:(+)(a) = 1
ERROR: cannot add methods to a builtin function

@cossio
Copy link
Contributor

cossio commented Oct 4, 2021

Something holding this back?

@tkf
Copy link
Member Author

tkf commented Oct 4, 2021

It's stuck because I haven't had time to work on what Jeff suggested. I'll close it for now so that others can pick it up without thinking about racing with me.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Add curried versions of === and !== Single argument isa function
5 participants