Skip to content
This repository was archived by the owner on Apr 1, 2025. It is now read-only.

Conversation

@robrix
Copy link
Contributor

@robrix robrix commented Jul 29, 2019

Our analyses are intended to be completely decoupled from the source language. This PR enables that by abstracting Analysis and various related signatures over the term type.

robrix added 30 commits July 29, 2019 11:49
Copy link
Contributor Author

@robrix robrix left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ready for review.

import Control.Effect.Reader hiding (Local)
import Control.Effect.State
import Control.Monad ((<=<), guard)
import qualified Data.Core as Core
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We no longer rely directly on imports of Data.Core or any other syntax. We do still rely on Analysis.Eval for the Analysis record, but it could easily be moved elsewhere (and will eventually be factored into effects anyway).

This means that we could in principle split the analyses off into a new package, which is a good sign that we’ve got the right separation of concerns going.

concrete
:: (Foldable term, Show (term User))
=> (forall sig m
. (Carrier sig m, Member (Reader Loc) sig, MonadFail m)
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Abstracting this evaluator over any m satisfying these effects (these being the effects required by eval) enables us to avoid coupling the evaluator(s) to implementation details of the analyses, too.

This list of constraints will eventually grow as we factor bits of Analysis out into effects.

. fix (eval concreteAnalysis)

concreteAnalysis :: ( Carrier sig m
, Foldable term
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We need Foldable to collect the free variables in the term to filter the env that closures close over.

, Semigroup value
)
=> Analysis address value m
=> Analysis (Term (Ann :+: Core) User) address value m
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

eval is still specialized to Term (Ann :+: Core) User; intuitively, it is the canonical abstract interpreter for Core, and thus has to be specialized to it.


type Cache name a = Map.Map (Term (Core.Ann :+: Core.Core) name) (Set.Set a)
type Heap name a = Map.Map name (Set.Set a)
newtype Cache term a = Cache { unCache :: Map.Map term (Set.Set a) }
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Without the newtype, abstracting the cache over the term type made it impossible to distinguish from Heap.

)
=> (Term (Core.Ann :+: Core.Core) name -> NonDetC (ReaderC (Cache name a) (StateC (Cache name a) m)) a)
-> Term (Core.Ann :+: Core.Core) name
=> proxy address
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We didn’t mention the address type anywhere else, so we needed a dummy parameter to keep it unambiguous. (We could also have used AllowAmbiguousTypes & TypeApplications, but I try to avoid the former since it makes calling the thing significantly more challenging.)

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

+1 on avoiding AllowAmbiguousTypes, since Proxy has nice behavior with TypeApplications anyway.

=> Analysis term User (Value term) m
-> (term -> m (Value term))
-> (term -> m (Value term))
)
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Most of the extra lines of code introduced by this PR are reformatted signatures + the evaluator parameters.

@robrix robrix marked this pull request as ready for review July 29, 2019 17:15
@robrix robrix requested a review from a team July 29, 2019 17:15
@robrix robrix mentioned this pull request Jul 30, 2019
7 tasks
@robrix robrix mentioned this pull request Aug 6, 2019
8 tasks
Copy link
Contributor

@patrickt patrickt left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Having a richer vocabulary to describe the capabilities of an analysis is such great stuff.

)
=> (Term (Core.Ann :+: Core.Core) name -> NonDetC (ReaderC (Cache name a) (StateC (Cache name a) m)) a)
-> Term (Core.Ann :+: Core.Core) name
=> proxy address
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

+1 on avoiding AllowAmbiguousTypes, since Proxy has nice behavior with TypeApplications anyway.

@robrix robrix changed the base branch from factor-annotations-out-of-core to master August 6, 2019 18:36
@patrickt patrickt merged commit 3f77dd6 into master Aug 6, 2019
@robrix robrix deleted the generalize-analyses-over-the-term-type branch August 6, 2019 18:55
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants