Zulip Chat Archive
Stream: metaprogramming / tactics
Topic: squeeze_simp - match failed?!
Eric Rodriguez (Jan 26 2022 at 11:55):
yeah, would much appreciate that. i'm currently really tempted to literally turn names into expr.const ff
s which feels outstandingly wrong
Eric Rodriguez (Jan 26 2022 at 15:28):
hmm, so okay, if you write squeeze_simp [_root_.asda, int.asda]
(using my MWE from above), you get that the simp_arg_list
has expr
s with the constructor local_const int.asda int.asda (...)
. So I tried replacing the resolve_name'
in name.to_simp_args
with get_local
, but now there isn't a int.asda
local; which makes sense, I guess, but then how did those original expr
s appear?
Arthur Paulino (Jan 26 2022 at 15:31):
I just found the time to sit with the problem. First, just to check if we have the same ideas, how do you expect the tactic to react in this scenario?
Also, can a mod move this thread to #metaprogramming / tactics ?
Eric Rodriguez (Jan 26 2022 at 15:31):
hmm, it seems that in the simp_arg_list
they are pexpr
s, but if I use get_local
I have no choice but to get expr
s. Is there any way to get pexpr
s?
Eric Rodriguez (Jan 26 2022 at 15:32):
I didn't know that was a stream!
Eric Rodriguez (Jan 26 2022 at 15:33):
The hope is that if you squeeze_simp
when you have something like int.asda, _root_.asda
in the used simpset, squeeze_simp
doesn't just crash completely. currently I've got a semi-working thing that doesn't crash, but prints try this: simp only [asda, asda]
so you have to guess namespaces
Eric Rodriguez (Jan 26 2022 at 15:39):
this also seems to work, but seems similarly wrong:
meta def name.to_simp_args (n : name) : tactic simp_arg_type :=
let h := @expr.local_const ff n n (default) (expr.var 1) in
do trace $ to_raw_fmt' h, return $ simp_arg_type.expr h
(ignore all the debugging stuff)
Arthur Paulino (Jan 26 2022 at 15:43):
But we're expecting it so say Try this: simp only [int.asda, asda, and_self]
, right?
Arthur Paulino (Jan 26 2022 at 15:43):
(even after open int
)
Eric Rodriguez (Jan 26 2022 at 15:43):
yes, with a _root_
on the second asda
because otherwise we'd get an overload resolution error
Eric Rodriguez (Jan 26 2022 at 15:44):
but honestly as long as it works, it's better than "match failed"
Arthur Paulino (Jan 26 2022 at 15:45):
I think name.to_simp_args
will need more information
Eric Rodriguez (Jan 26 2022 at 15:48):
doesn't it have the tactic state by virtue of being a tactic monad?
Arthur Paulino (Jan 26 2022 at 15:52):
Right
Arthur Paulino (Jan 26 2022 at 15:55):
Eric Rodriguez said:
The hope is that if you
squeeze_simp
when you have something likeint.asda, _root_.asda
in the used simpset,squeeze_simp
doesn't just crash completely. currently I've got a semi-working thing that doesn't crash, but printstry this: simp only [asda, asda]
so you have to guess namespaces
How did you accomplish this?
Eric Rodriguez (Jan 26 2022 at 15:55):
you can see in my branch right now, but I just hand-craft the pexpr
Arthur Paulino (Jan 26 2022 at 15:56):
Oops, I forgot to change branches (I was on master
:face_palm: )
Arthur Paulino (Jan 26 2022 at 16:03):
Alright, this is a good step. Now we need to do something about duplicated occurrences
Arthur Paulino (Jan 26 2022 at 17:05):
Actually I think this is the best approach:
a
resolve_name'
that will keep in the_root_
Eric Rodriguez (Jan 26 2022 at 17:28):
resolve_name
is c++, is the issue
Eric Rodriguez (Jan 26 2022 at 17:37):
honestly, maybe my latest approach with declaring them as a local_const ff
is the right approach; that's how they're going to be read in the context, and if they don't work as a local_const ff
then they just won't work at all
Eric Rodriguez (Jan 26 2022 at 17:38):
maybe the only thing missing is to also add prepend_root_if_needed
to the tactic format name
Arthur Paulino (Jan 26 2022 at 17:44):
yeah I was trying to write a resolve_name''
that incorporates prepend_root_if_needed
Arthur Paulino (Jan 26 2022 at 17:45):
and drop this line from squeeze_simp_core
:
vs ← vs.mmap prepend_root_if_needed,
Arthur Paulino (Jan 26 2022 at 20:24):
@Eric Rodriguez maybe we can have more control this way?
meta def name.to_simp_args' (n : name) : tactic simp_arg_type :=
do x ← resolve_name' n,
return $ match x with
| expr.macro m l := -- m and l might add in some useful info?
-- simp_arg_type.expr $ pexpr.mk_field_macro (@expr.const ff n []) `_root
-- simp_arg_type.expr (@expr.macro ff m ([`_root_, n].map (λ n', to_pexpr $ mk_local n')))
simp_arg_type.expr (@expr.const ff (`_root_ ++ n) [])
| _ :=
simp_arg_type.expr (@expr.const ff n [])
end
Eric Rodriguez (Jan 26 2022 at 20:48):
ooh, maybe this is the right way. maybe we can make it a function that is resolve_name'
usually, but in the case of an overload it just prepends _root_
?
Arthur Paulino (Jan 26 2022 at 21:14):
oof, I'm stuck
Eric Rodriguez (Jan 26 2022 at 21:30):
what's the issue?
Arthur Paulino (Jan 26 2022 at 21:30):
Okay, this approach won't help.
When tracing (@expr.const ff (
_root_ ++ n) [])` it prints:
_root_.int.asda
_root_.asda
_root_.and_self
Each of those is the consumed by simp_arg_type.expr : pexpr → simp_arg_type
Then, right after that, when tracing the results, it says:
[asda, asda, and_self]
So I believe something is happening inside simp_arg_type.expr
that's getting rid of _root_
without mercy
Arthur Paulino (Jan 26 2022 at 21:31):
I'm resetting my branch to the state where you left it at
Eric Rodriguez (Jan 26 2022 at 21:47):
that's just the pretty printer
Arthur Paulino (Jan 26 2022 at 21:47):
Hm
Eric Rodriguez (Jan 26 2022 at 21:47):
if you change the has_to_string
instance to use to_raw_fmt
, you'll see that it's still the right place
Eric Rodriguez (Jan 26 2022 at 21:47):
we do need to fight it at the end, but again I think even just getting asda, asda
is an improvement over a crash
Eric Rodriguez (Jan 26 2022 at 21:48):
especially because at that point Lean will throw all the possible overloads at you and you can start to figure it out
Eric Rodriguez (Jan 26 2022 at 21:48):
it'd be nice to not have to do that but the pp works in mysterious ways
Arthur Paulino (Jan 26 2022 at 21:52):
Maybe simp_arg_type
needs something like dotted_expr
?
Eric Rodriguez (Jan 26 2022 at 21:52):
the issue isn't simp_arg_type
, it's expr
's to_string
Arthur Paulino (Jan 26 2022 at 21:55):
but how would we indicate that to_string
is not supposed to strip _root_
?
Eric Rodriguez (Jan 26 2022 at 21:55):
make a custom to_string
, I think
Arthur Paulino (Jan 26 2022 at 21:56):
In C?
Arthur Paulino (Jan 26 2022 at 22:02):
What if prepend_root_if_needed
returns tactic (name × bool)
indicating which ones needed the prepend?
Eric Rodriguez (Jan 26 2022 at 22:02):
i was thinking that and think it's a good idea
Eric Rodriguez (Jan 26 2022 at 22:02):
I was hoping we could swap the pp
in mk_suggestion
for a different method so we don't have to worry about this
Eric Rodriguez (Jan 26 2022 at 22:03):
but >>=
is not one of the two monadic operators I know
Arthur Paulino (Jan 26 2022 at 22:03):
I'm gonna brb, please let me know if this works
Eric Rodriguez (Jan 26 2022 at 22:07):
image.png hmm, I think you're right that we just need to keep track of root
independently
Eric Rodriguez (Jan 26 2022 at 22:08):
I think the fix can be two-fold - keep track of _root_
independently, and use to_string
instead of pp
Eric Rodriguez (Jan 26 2022 at 22:08):
i'll try this in a little bit and see what happens
Arthur Paulino (Jan 26 2022 at 22:20):
Use to_string then the bool returns true, right? Otherwise use pp
Eric Rodriguez (Jan 26 2022 at 22:22):
no, pp
also cuts off the int.
(presumably because it's open)
Arthur Paulino (Jan 26 2022 at 22:24):
Ah, right
Arthur Paulino (Jan 26 2022 at 23:23):
Wait, I think it worked?
image.png
Eric Rodriguez (Jan 26 2022 at 23:25):
omg! this is great news! what did you end up doing?
Arthur Paulino (Jan 26 2022 at 23:26):
This is weird, I didn't do anything different from https://leanprover.zulipchat.com/#narrow/stream/239415-metaprogramming-.2F.20tactics/topic/squeeze_simp.20-.20match.20failed.3F!/near/269490059
Eric Rodriguez (Jan 26 2022 at 23:27):
ooh, I changed the to_string
to to_raw_fmt
for debugging
Eric Rodriguez (Jan 26 2022 at 23:27):
I should've checked it without that!!
Arthur Paulino (Jan 26 2022 at 23:28):
wanna push? you solved it haha
Eric Rodriguez (Jan 26 2022 at 23:28):
no dw you were a massive help^^ I've got another branch open right now, too, so it'd be a massive pain ;b
Arthur Paulino (Jan 26 2022 at 23:29):
This is the exact git diff:
$ git diff
diff --git a/src/tactic/squeeze.lean b/src/tactic/squeeze.lean
index 20bad3d651..fa4bf57038 100644
--- a/src/tactic/squeeze.lean
+++ b/src/tactic/squeeze.lean
@@ -80,7 +80,7 @@ run_cmd squeeze_loc_attr.set ``squeeze_loc_attr_carrier none tt
list entirely if it is empty. -/
meta def render_simp_arg_list : list simp_arg_type → tactic format
| [] := pure ""
-| args := (++) " " <$> to_line_wrap_format <$> args.mmap pp
+| args := (++) " " <$> to_line_wrap_format <$> pure (args.map to_string)
/-- Emit a suggestion to the user. If inside a `squeeze_scope` block,
the suggestions emitted through `mk_suggestion` will be aggregated so that
:joy:
Arthur Paulino (Jan 26 2022 at 23:29):
Just that
Arthur Paulino (Jan 26 2022 at 23:32):
I am also going to document why pp
was problematic in the docstring of render_simp_arg_list
Kevin Buzzard (Jan 26 2022 at 23:35):
Wanna try #3097 next?
Eric Rodriguez (Jan 26 2022 at 23:37):
oh, christ, I always assumed simp
lemmas were order independent... i'll have a dig. also huge thanks to Rob for the metaprogramming in Lean stuff, I would've never gotten my head around this without him
Arthur Paulino (Jan 26 2022 at 23:44):
Makes sense?
Patch:
pp
was changed toto_string
because it was getting rid of prefixes
that would be necessary for some disambiguations.
Alex J. Best (Jan 26 2022 at 23:46):
For #3097 maybe squeeze simp could just check its output works (either in the sense of not failing or in the sense of giving the same result as the original simp call), seeing as this should be a simp only it may well be fast enough, and otherwise apply a random permutation and try again.
Eric Rodriguez (Jan 26 2022 at 23:53):
ahh, bogosort ;b
Arthur Paulino (Jan 26 2022 at 23:58):
#11659 should be ready for review already :octopus:
Eric Rodriguez (Jan 27 2022 at 00:02):
@Kevin Buzzard, do you know if the issue can happen with non-rfl
lemmas?
Eric Rodriguez (Jan 27 2022 at 00:02):
it may be a bit easier to debug it that way
Arthur Paulino (Jan 27 2022 at 00:04):
If we want squeeze_simp
to try harder, maybe we can't do much better than trying every permutation?
Arthur Paulino (Jan 27 2022 at 00:12):
I think we could continue the conversation about the other issue here and ask a mod to move that thread to this stream as well
Kevin Buzzard (Jan 27 2022 at 09:16):
I don't know anything, I just keep track of times when squeeze_simp fails because this causes problems for my students!
Arthur Paulino (Jan 27 2022 at 15:35):
The fix is ready for review #11696
@Rob Lewis can you also take a look at this one? :pray:
Rob Lewis (Jan 27 2022 at 16:01):
I'll find time later today!
Julian Berman (Jan 27 2022 at 19:26):
OT: Arthur you are quite inspiring :)
Last updated: Dec 20 2023 at 11:08 UTC