Mikan
Safe HaskellNone
LanguageHaskell2010

Mikan.Syntax.Scope.Trimming

Synopsis

Definition liveness & copy trimming

The purpose of these operations is to let the type checker know what definition copies are actually used for type-checking and need to be created, and which can be safely skipped ("trimmed", hence the name renTrimming).

The liveness the scope-checker reports should be a conservative over-approximation of what names are actually used. For example, when an overloaded field/constructor name is resolved, we (have to) mark all of the names in the set as used: not only do we not know which one the type checker will actually pick, but the type checker will ask for all of their getConstInfo when disambiguating.

Marking a name as live is done through the markLiveName function, which is called from resolveName', so any names coming from concrete syntax will already be marked live. However, if potential references to copies are being inserted "synthetically" by the scope checker, they must be referred to by an explicit markLiveName call.

Module names can also be markLiveNamed, and this has the effect of transitively saving every definition having that module as a prefix.

newScopeCopyRef :: ModuleName -> ScopeM ScopeCopyRef Source #

Create a new reference to store liveness information for names in the given copied module.

copyName :: ScopeCopyRef -> QName -> QName -> ScopeM () Source #

Mark a name as being a copy in the TC state, associating it with the given ScopeCopyRef for liveness information.

class MarkLive n where Source #

Class for entities which contain names that can be marked live. The two fundamental instances are QNames and ModuleNames, but there are some convenience instances for things like ResolvedNames.

Minimal complete definition

Nothing

Methods

markLiveName :: n -> ScopeM () Source #

Mark a name as (potentially) having been used.

default markLiveName :: forall (t :: Type -> Type) n'. (Traversable t, n ~ t n', MarkLive n') => n -> ScopeM () Source #

Instances

Instances details
MarkLive AbstractName Source # 
Instance details

Defined in Mikan.Syntax.Scope.Trimming

MarkLive ModuleName Source # 
Instance details

Defined in Mikan.Syntax.Scope.Trimming

MarkLive QName Source # 
Instance details

Defined in Mikan.Syntax.Scope.Trimming

Methods

markLiveName :: QName -> ScopeM () Source #

MarkLive ResolvedName Source # 
Instance details

Defined in Mikan.Syntax.Scope.Trimming

MarkLive n => MarkLive (List1 n) Source # 
Instance details

Defined in Mikan.Syntax.Scope.Trimming

Methods

markLiveName :: List1 n -> ScopeM () Source #

sameTrimming :: ScopeCopyInfo -> ScopeCopyInfo -> ScopeM Bool Source #

Compare the trimming from an old ScopeCopyInfo with a new one.

clobberLiveNames :: ScopeM () Source #

Replaces the LiveNames in every module application in the scope-checker state at this point with AllLiveNames, effectively disabling copy trimming for the modules we have seen so far.

onlyLiveCopies :: ModuleName -> ScopeCopyInfo -> TCM (Ren QName, ScopeCopyInfo) Source #

Filter a ScopeCopyInfo to only those names which were explicitly referred to by the programmer.

Returns the new ScopeCopyInfo and the complement of the definition renaming, i.e. the names that were pruned.