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
Evaluate private definitions (toplevel interaction) #4647
Comments
May be worth having a distinct command "evaluate in context at cursor". |
That would require us to store the context of every subterm, which I don't think is really feasible. |
I do believe we have the "inside scope" available, that is the scope that would be used for any new definitions at the end of the module. It ought not be too difficult to use this instead of the "outside scope", which is what other modules importing this module sees. |
I mean, what @gallais proposes is the holy grail of interactive theorem provers. |
Related: #317. I wrote that 'I think the parameters should be in scope when "top-level" commands are executed, because these commands should behave in the same way as commands executed in a top-level goal at the end of the module'. |
We do use the inside scope. However, the private definitions are removed from the agda/src/full/Agda/Syntax/Translation/ConcreteToAbstract.hs Lines 1232 to 1236 in bc8feec
You changed this in the course of the "deadcode" optimizations:
So while the OP used to work, there was a decision made to sacrifice it for the sake of performance. It seems there are three interest pursued which cannot all be integrated with the current architecture:
A possible fix (Alt A) could look like this: There are two different formats of the interface file, one that includes the private definitions (2) (say An alternative fix (Alt B) would drop goal 2 and remove private definition only just before serialization. The current main module (in its internal representation) would then always be created from source, rather than loaded from an interface. However, this has the drawback that switching file in emacs would always mean that the whole file is type-checked again from scratch. @nad has complained about such behavior in the past. Yet currently, rechecking is anyway often needed because the highlighting is not reliably loaded from the interface file, see issue #3549. Input needed from @UlfNorell (defined the current specified behavior) and @nad (expertise on import and interaction logic). |
What about Alt B, but we add an emacs command to switch between "evaluation mode" (not using the interface for the current file) and "regular mode" (the normal behaviour). This should solve the drawback when switching files, if we reset the to regular mode when changing buffer. |
|
Also checking should be quick due to caching, no? |
Note: It seems the present issue is a duplicate of #1804. |
The other option seems to be not to strip private definitions. Why is this so important? |
For performance: #1804 (comment) |
FindFile: more precise type for toIFile
Another option is perhaps to switch to some kind of structured signature so that the optimisation is not necessary. This may also have other performance benefits (#4331). |
@nad:
The problem isn't in the signature but in the scope. The private declarations get removed from the
I am implementing this, but this will be disruptive to some interaction tests that accumulate solutions for metas (e.g. |
These values helped me trace the missing highlighting introduced by the load caused by top-level interaction commands to the agda mode, which supplied "None" as highlighting level to these commands.
This commit addresses the problem that interaction commands that run in the top-level, like C-c C-n, do not have access to private decls of the main module. These are deleted from the scope before serialization, for reasons of performance (see #1806). The solution implemented here is that interaction gets two modes: 1. RegularInteraction: Initial mode after C-c C-l. The internal representation of the top module, hence its insideScope, is loaded from the interface file and thus has no knowledge of private declarations. 2. TopLevelInteraction: Top-level interaction commands switch to this mode, leading to a reload of the current top module in a way that private declarations are preserved in the insideScope. The module is not serialized. When a new file is loaded, we switch back to RegularInteraction. The emacs mode had to be changed to switch on highlighting for top-level commands, which was off because no highlighting would happen. Now, highlighting can happen due to a reload.
Due to more reloads caused by top-level commands, the interaction test output can more noisy: More status reports.
These interaction tests now produce the expected results (fruits of fixing #4647).
These interaction tests are broken by the fix of #4647, due to the additional reloads triggered by top-level commands. Solutions given to metas by interaction commands get lost by reloads, since they are not incorporated into the source file (naturally). The situation is now similar to why case splits do no update the state of the interaction.
PR #4652 for review. |
With this change in place, if I load the file, edit it, and use a top-level command to (say) normalise an expression, will Agda reload the file (and possibly fail)? In that case I am opposed to this change. |
These values helped me trace the missing highlighting introduced by the load caused by top-level interaction commands to the agda mode, which supplied "None" as highlighting level to these commands.
This commit addresses the problem that interaction commands that run in the top-level, like C-c C-n, do not have access to private decls of the main module. These are deleted from the scope before serialization, for reasons of performance (see #1806). The solution implemented here is that interaction gets two modes: 1. RegularInteraction: Initial mode after C-c C-l. The internal representation of the top module, hence its insideScope, is loaded from the interface file and thus has no knowledge of private declarations. 2. TopLevelInteraction: Top-level interaction commands switch to this mode, leading to a reload of the current top module in a way that private declarations are preserved in the insideScope. The module is not serialized. When a new file is loaded, we switch back to RegularInteraction. The emacs mode had to be changed to switch on highlighting for top-level commands, which was off because no highlighting would happen. Now, highlighting can happen due to a reload.
Due to more reloads caused by top-level commands, the interaction test output can more noisy: More status reports.
These interaction tests now produce the expected results (fruits of fixing #4647).
These interaction tests are broken by the fix of #4647, due to the additional reloads triggered by top-level commands. Solutions given to metas by interaction commands get lost by reloads, since they are not incorporated into the source file (naturally). The situation is now similar to why case splits do no update the state of the interaction.
Catch not-in-scope errors in top-level interaction commands such as C-c C-d infer C-c C-n evaluate C-c C-o module contents C-c C-w why in scope and try to handle by reloading file in TopLevelInteraction mode that preserves the private declarations. Caveat: commands that do not throw scope errors such as C-c C-z search about will by default (RegularInteraction) not include the private declarations, only if some other top-level command switches to TopLevelInteraction, then the private declarations will also be listed.
This commit addresses the problem that interaction commands that run in the top-level, like C-c C-n, do not have access to private decls of the main module. These are deleted from the scope before serialization, for reasons of performance (see #1806). The solution implemented here is that interaction gets two modes: 1. RegularInteraction: Initial mode after C-c C-l. The internal representation of the top module, hence its insideScope, is loaded from the interface file and thus has no knowledge of private declarations. 2. TopLevelInteraction: Top-level interaction commands switch to this mode, leading to a reload of the current top module in a way that private declarations are preserved in the insideScope. The module is not serialized. When a new file is loaded, we switch back to RegularInteraction. The emacs mode had to be changed to switch on highlighting for top-level commands, which was off because no highlighting would happen. Now, highlighting can happen due to a reload. UPDATE: only switch to TopLevelInteraction when NotInScope error. Catch not-in-scope errors in top-level interaction commands such as C-c C-d infer C-c C-n evaluate C-c C-o module contents C-c C-w why in scope and try to handle by reloading file in TopLevelInteraction mode that preserves the private declarations. Caveat: commands that do not throw scope errors such as C-c C-z search about will by default (RegularInteraction) not include the private declarations, only if some other top-level command switches to TopLevelInteraction, then the private declarations will also be listed. Note: Top-level commands that lead to a reload have to be used with care in interaction tests. Solutions given to metas by interaction commands get lost by reloads, since they are not incorporated into the source file (naturally). The situation is now similar to why case splits do no update the state of the interaction. Instructions how to revert ... ------------------------------ ... the changes introduced in interaction that are introduced by this patch: A simple `git revert` won't do since there are code improvements contained in this patch that should not be reverted. However, a manual revert is: remove data type Agda.Interaction.Base.InteractionMode and go with the flow. Any choices that use this bit should collapsed as if there was only the value RegularInteraction
Should the new behavior of top-level interaction commands (reload on not-in-scope errors) be disruptive to one's workflow, this option brings back the old behavior (with private declarations not in scope).
These values helped me trace the missing highlighting introduced by the load caused by top-level interaction commands to the agda mode, which supplied "None" as highlighting level to these commands.
This commit addresses the problem that interaction commands that run in the top-level, like C-c C-n, do not have access to private decls of the main module. These are deleted from the scope before serialization, for reasons of performance (see #1806). The solution implemented here is that interaction gets two modes: 1. RegularInteraction: Initial mode after C-c C-l. The internal representation of the top module, hence its insideScope, is loaded from the interface file and thus has no knowledge of private declarations. 2. TopLevelInteraction: Top-level interaction commands switch to this mode, leading to a reload of the current top module in a way that private declarations are preserved in the insideScope. The module is not serialized. When a new file is loaded, we switch back to RegularInteraction. The emacs mode had to be changed to switch on highlighting for top-level commands, which was off because no highlighting would happen. Now, highlighting can happen due to a reload. UPDATE: only switch to TopLevelInteraction when NotInScope error. Catch not-in-scope errors in top-level interaction commands such as C-c C-d infer C-c C-n evaluate C-c C-o module contents C-c C-w why in scope and try to handle by reloading file in TopLevelInteraction mode that preserves the private declarations. Caveat: commands that do not throw scope errors such as C-c C-z search about will by default (RegularInteraction) not include the private declarations, only if some other top-level command switches to TopLevelInteraction, then the private declarations will also be listed. Note: Top-level commands that lead to a reload have to be used with care in interaction tests. Solutions given to metas by interaction commands get lost by reloads, since they are not incorporated into the source file (naturally). The situation is now similar to why case splits do no update the state of the interaction. Instructions how to revert ... ------------------------------ ... the changes introduced in interaction that are introduced by this patch: A simple `git revert` won't do since there are code improvements contained in this patch that should not be reverted. However, a manual revert is: remove data type Agda.Interaction.Base.InteractionMode and go with the flow. Any choices that use this bit should collapsed as if there was only the value RegularInteraction
Should the new behavior of top-level interaction commands (reload on not-in-scope errors) be disruptive to one's workflow, this option brings back the old behavior (with private declarations not in scope).
I have merged the PR to subject it to testing in practice. @nad : Please use Agda "naturally" (as you always use it) and see if any disruption of your workflows happens in practice. There is an "emergency brake", option |
FindFile: more precise type for toIFile
These values helped me trace the missing highlighting introduced by the load caused by top-level interaction commands to the agda mode, which supplied "None" as highlighting level to these commands.
This commit addresses the problem that interaction commands that run in the top-level, like C-c C-n, do not have access to private decls of the main module. These are deleted from the scope before serialization, for reasons of performance (see agda#1806). The solution implemented here is that interaction gets two modes: 1. RegularInteraction: Initial mode after C-c C-l. The internal representation of the top module, hence its insideScope, is loaded from the interface file and thus has no knowledge of private declarations. 2. TopLevelInteraction: Top-level interaction commands switch to this mode, leading to a reload of the current top module in a way that private declarations are preserved in the insideScope. The module is not serialized. When a new file is loaded, we switch back to RegularInteraction. The emacs mode had to be changed to switch on highlighting for top-level commands, which was off because no highlighting would happen. Now, highlighting can happen due to a reload. UPDATE: only switch to TopLevelInteraction when NotInScope error. Catch not-in-scope errors in top-level interaction commands such as C-c C-d infer C-c C-n evaluate C-c C-o module contents C-c C-w why in scope and try to handle by reloading file in TopLevelInteraction mode that preserves the private declarations. Caveat: commands that do not throw scope errors such as C-c C-z search about will by default (RegularInteraction) not include the private declarations, only if some other top-level command switches to TopLevelInteraction, then the private declarations will also be listed. Note: Top-level commands that lead to a reload have to be used with care in interaction tests. Solutions given to metas by interaction commands get lost by reloads, since they are not incorporated into the source file (naturally). The situation is now similar to why case splits do no update the state of the interaction. Instructions how to revert ... ------------------------------ ... the changes introduced in interaction that are introduced by this patch: A simple `git revert` won't do since there are code improvements contained in this patch that should not be reverted. However, a manual revert is: remove data type Agda.Interaction.Base.InteractionMode and go with the flow. Any choices that use this bit should collapsed as if there was only the value RegularInteraction
Should the new behavior of top-level interaction commands (reload on not-in-scope errors) be disruptive to one's workflow, this option brings back the old behavior (with private declarations not in scope).
This commit unfixes #4647 by removing the `InteractionMode` (`TopLevelInteraction`/`RegularInteraction`) and the option to switch off the logic (which didn't fully work). For #4647 there is a simple workaround: add a hole to the file so that the interface is not serialize and thus the private definitions are not removed.
This commit unfixes #4647 by removing the `InteractionMode` (`TopLevelInteraction`/`RegularInteraction`) and the option to switch off the logic (which didn't fully work). For #4647 there is a simple workaround: add a hole to the file so that the interface is not serialize and thus the private definitions are not removed.
This commit unfixes #4647 by removing the `InteractionMode` (`TopLevelInteraction`/`RegularInteraction`) and the option to switch off the logic (which didn't fully work). For #4647 there is a simple workaround: add a hole to the file so that the interface is not serialize and thus the private definitions are not removed.
This commit unfixes #4647 by removing the `InteractionMode` (`TopLevelInteraction`/`RegularInteraction`) and the option to switch off the logic (which didn't fully work). For #4647 there is a simple workaround: add a hole to the file so that the interface is not serialize and thus the private definitions are not removed.
This commit unfixes #4647 by removing the `InteractionMode` (`TopLevelInteraction`/`RegularInteraction`) and the option to switch off the logic (which didn't fully work). For #4647 there is a simple workaround: add a hole to the file so that the interface is not serialize and thus the private definitions are not removed.
I undid the fix. A workaround (in many cases) is to leave a hole in the file one wants to issue top-level interaction commands. |
Private definitions cannot be evaluated in interaction top level:
Then
C-c C-n n
gives an error complaining thatn
is not in scope.The same problem arises with non-
public
open
.Here is Thorsten Altenkirch's original feature request:
I have come across this little nuisance when using agda especially when doing life hacking in lectures or talks.
I try to evaluate an expression which depends on opening some modules which I have opened in my file but agda is not aware of this. E.g.
And then I say
C-c C-n hd (from 0)
and agda respondsOk I can just introduce a shed
and evaluate inside there but this is a bit clumsy. Isn’t there a better way to do this?
Ok I can say
open Stream public
– but do I want this?The text was updated successfully, but these errors were encountered: