Making debug toggles more efficient #3274
Merged
+4,272
−4,315
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.
Currently, to check if a given debug_level is enabled for a given module, we need to traverse two lists (see
Options.debug_at_level
) comparing each element for equality. This is not normally bad, as both lists are empty, but as soon as we set any kind of debugging everything becomes slower. Compare for instance:adding more flags makes it worse.
This PR introduces a new
FStar.Compiler.Debug
in which we can register debug toggles, at initialization time, and then query them in constant time. The main function of interest is nowwhich can (and should only) be called from a top-level definition to obtain a reference. Calling
get_toggle
repeatedly with the same key will return the exact same reference, so many modules can use the same key without coordinating. (This function can be made more efficient --it's currently traversing a list-- but it anyway happens only once, during program startup time.) Then, the toggle can be queried just by looking at the reference. See this for how to use it:With this change performance is much better:
--
I also changed the behavior of --debug. Now it takes toggle names (or Low/High/Medium/Extreme) instead of a module. F* assumes you're only interested in debugging the current module (i.e. whenever
Options.should_check()
) is on, but you can also provide--debug_all_modules
to force debugging everywhere. The logic handling this is inFStar.TypeChecker.Tc
, which resets the debug toggles when switching modules.Another advantage is that we can now list all toggles easily, as they registered during program initialization. So I added
--list_debug_keys
:Something to consider is whether we should add some hierarchy to the keys.