-
Notifications
You must be signed in to change notification settings - Fork 338
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
Performance: Instantiated meta-variables in interface files #5731
Comments
I have optimised this piece of code. However, the main problem remains. |
One should at least also include bindings for the instantiated meta-variables in the interfaces. Are meta-variable identifiers only unique within a single module? In that case that should also be addressed in some way. |
Yes, metavariables are currently only unique within the same top-level module, so they should be qualified properly. One more advantage of allowing metas in interfaces would be that it would allow us to get rid of the current ugly hack in the implementation of |
I was wondering how much of the agda/src/full/Agda/TypeChecking/Monad/Base.hs Line 1312 in 1fe6beb
A agda/src/full/Agda/TypeChecking/Monad/Base.hs Lines 1272 to 1284 in 1fe6beb
Do we need any of this, except for the instantiation, for instantiated meta-variables from other modules? Such meta-variables could be seen as shorthand notation for their instantiations, and the code that replaces instantiated meta-variables with their instantiations only uses agda/src/full/Agda/TypeChecking/Reduce.hs Lines 142 to 172 in 1fe6beb
It might be easier to just store the entire agda/src/full/Agda/Interaction/Imports.hs Line 1006 in 1fe6beb
An alternative might be to treat instantiated meta-variables differently from other ones. |
I located some pieces of code that are at least linear in the size of the meta-store (if everything is evaluated strictly).
|
In general, no: the closed metas are used in that function (grep for |
OK, perhaps one could replace (the relevant instance of) agda/src/full/Agda/TypeChecking/Generalize.hs Lines 161 to 164 in 3a63943
Do you know if agda/src/full/Agda/TypeChecking/Generalize.hs Lines 129 to 136 in 3a63943
Given code like the following (inside agda/src/full/Agda/TypeChecking/Rules/Term.hs Lines 131 to 132 in 3a63943
Another question: Is all the information in |
I found a simple way to optimise |
Don't forget to add a test case to test what happens when they wrap around! |
Some things that remain to be done:
|
Sometimes there are interaction points corresponding to solved meta-variables. I guess that |
I'm thinking of changing the representation of agda/src/full/Agda/Syntax/Common.hs Lines 2331 to 2333 in 382861b
What promises do we make about the results of the following functions? agda/src/data/lib/prim/Agda/Builtin/Reflection.agda Lines 83 to 84 in 382861b
|
@jespercockx, @UlfNorell: Do we not make any promises (other than injectivity)? |
I think the "promise" (if you want to call it that) is that the |
I think it would be good if you could still use those functions to implement a pretty printer for |
I suppose that the implementations should match the implementations in |
Well, about that... open import Agda.Builtin.IO
open import Agda.Builtin.List
open import Agda.Builtin.Reflection renaming (bindTC to _>>=_)
open import Agda.Builtin.String
open import Agda.Builtin.Unit
macro
getMeta : Term → TC ⊤
getMeta hole@(meta m _) = quoteTC m >>= unify hole
getMeta _ = typeError []
myMeta : Meta
myMeta = getMeta
postulate putStrLn : String → IO ⊤
{-# FOREIGN GHC import qualified Data.Text as T #-}
main : IO ⊤
main = putStrLn (primShowMeta myMeta) Trying to compile this with the GHC backend this produces an internal error:
|
Please open a separate issue for that bug. |
Is it a problem if the numbers created by |
I think they're just meant to be unique identifiers, so I would really hope no-one ever recurses on them. |
I do not know if the calls to lookupLocalMeta in Agda.Auto.Auto and Agda.Auto.Convert are "safe" in the sense that they will never be performed for a remote meta-variable. I received some help from Andreas Abel, Jesper Cockx and Ulf Norell.
And changed the type of the field metaId from Nat to Word64. When a MetaId is converted to JSON the metaModule field is included in the output.
I do not know if the calls to lookupLocalMeta in Agda.Auto.Auto and Agda.Auto.Convert are "safe" in the sense that they will never be performed for a remote meta-variable. I received some help from Andreas Abel, Jesper Cockx and Ulf Norell.
I received some help from Andreas Abel, Jesper Cockx and Ulf Norell.
I opted to replace the calls to
Done. |
I received some help from Andreas Abel, Jesper Cockx and Ulf Norell.
And changed the type of the field metaId from Nat to Word64. When a MetaId is converted to JSON the metaModule field is included in the output.
I received some help from Andreas Abel, Jesper Cockx and Ulf Norell.
AIMXXXVII: @AndrasKovacs is working on sharing metas and, to this end, printing of interfaces, and noticed that there are no metas in definitions even with agda/src/full/Agda/TypeChecking/Rules/Def.hs Lines 357 to 362 in 4460544
The absence of metas would explain the lack of performance gain by --save-metas , and the slight increase of the size of the interface files. Meta solutions are then stored, taking some space, but since no meta solutions are reused, there are no savings.
|
@UlfNorell and I added that call to |
I'm currently working on some code for which Agda fails to create the interface. I think my code should be optimised, but I want to document the problem. Agda spends a lot of time instantiating meta-variables when eliminating dead code, before running out of memory:
agda/src/full/Agda/TypeChecking/DeadCode.hs
Lines 23 to 29 in ff89beb
Note that meta-variables are also instantiated before the interface is stored (presumably this piece of code could be optimised):
agda/src/full/Agda/Interaction/Imports.hs
Lines 1198 to 1200 in ff89beb
Would it make sense to have instantiated meta-variables in interfaces? Could this lead to any problems? I can imagine that the problem with the freezing code (#5388) could be made worse.
The text was updated successfully, but these errors were encountered: