Skip to content

Commit

Permalink
Minor renaming and rearrangements (#51)
Browse files Browse the repository at this point in the history
* More imports API changes

* Beta-normalize before alpha-normalization in tests

* Update README
  • Loading branch information
travisbrown authored Apr 21, 2020
1 parent 558f55c commit 73c8f16
Show file tree
Hide file tree
Showing 7 changed files with 25 additions and 25 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -406,7 +406,7 @@ It requires a bit of ceremony to set up:
```scala
import cats.effect.{ContextShift, IO, Resource}
import org.dhallj.core.Expr
import org.dhallj.imports._
import org.dhallj.imports.syntax._
import org.dhallj.parser.DhallParser
import org.http4s.client.Client
import org.http4s.client.blaze.BlazeClientBuilder
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,23 +4,23 @@ import cats.effect.Sync
import org.dhallj.core.Expr
import org.http4s.client.Client

object ResolveImports {
def apply[F[_] <: AnyRef](expr: Expr)(implicit Client: Client[F], F: Sync[F]): F[Expr] =
object Resolver {
def resolve[F[_] <: AnyRef](expr: Expr)(implicit Client: Client[F], F: Sync[F]): F[Expr] =
F.flatMap(ResolveImportsVisitor[F])(expr.accept(_))

def apply[F[_] <: AnyRef](
def resolve[F[_] <: AnyRef](
semanticCache: ImportCache[F],
semiSemanticCache: ImportCache[F]
)(expr: Expr)(implicit Client: Client[F], F: Sync[F]): F[Expr] =
expr.accept(ResolveImportsVisitor[F](semanticCache, semiSemanticCache))

def apply[F[_] <: AnyRef](
def resolve[F[_] <: AnyRef](
semanticCache: ImportCache[F]
)(expr: Expr)(implicit Client: Client[F], F: Sync[F]): F[Expr] =
expr.accept(ResolveImportsVisitor[F](semanticCache, new ImportCache.NoopImportCache))
expr.accept(ResolveImportsVisitor[F](semanticCache, new ImportCache.NoopImportCache[F]))

final class Ops(val expr: Expr) extends AnyVal {
def resolveImports[F[_] <: AnyRef](implicit Client: Client[F], F: Sync[F]): F[Expr] =
ResolveImports.apply[F](expr)
resolve[F](expr)
}
}

This file was deleted.

Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
package org.dhallj.imports

import org.dhallj.core.Expr

package object syntax {
implicit def toResolveImportOps(expr: Expr): Resolver.Ops = new Resolver.Ops(expr)
}
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import cats.implicits._
import munit.FunSuite
import org.dhallj.core.Expr
import org.dhallj.core.binary.Decode
import org.dhallj.imports.syntax._
import org.dhallj.parser.DhallParser.parse
import org.http4s.client._
import org.http4s.client.blaze._
Expand Down Expand Up @@ -149,7 +150,7 @@ class ImportResolutionSuite extends FunSuite {
val expr = parse(
"classpath:/hashed/package.dhall sha256:d60d8415e36e86dae7f42933d3b0c4fe3ca238f057fba206c7e9fbf5d784fe15"
)
val expected = parse("let x = 1 in x").alphaNormalize.normalize
val expected = parse("let x = 1 in x").normalize.alphaNormalize

assert(resolve(expr) == expected)
}
Expand All @@ -159,7 +160,7 @@ class ImportResolutionSuite extends FunSuite {
val expr = parse(
"let x = classpath:/hashed/package.dhall sha256:e60d8415e36e86dae7f42933d3b0c4fe3ca238f057fba206c7e9fbf5d784fe15 in x"
)
val expected = parse("let x = 1 in x").alphaNormalize.normalize
val expected = parse("let x = 1 in x").normalize.alphaNormalize

assert(resolve(expr) == expected)
}
Expand All @@ -168,7 +169,7 @@ class ImportResolutionSuite extends FunSuite {
val cache = InMemoryCache()

val expected = parse("let x = 2 in x")
val encoded = expected.alphaNormalize.normalize.getEncodedBytes
val encoded = expected.normalize.alphaNormalize.getEncodedBytes
val hash = MessageDigest.getInstance("SHA-256").digest(encoded)

val expr =
Expand All @@ -184,7 +185,7 @@ class ImportResolutionSuite extends FunSuite {

val cached = parse("let x = 1 in x")
val expected = parse("let x = 2 in x")
val encoded = cached.alphaNormalize.normalize.getEncodedBytes
val encoded = cached.normalize.alphaNormalize.getEncodedBytes
val hash = MessageDigest.getInstance("SHA-256").digest(expected.normalize.getEncodedBytes) //Hash doesn't match what is stored

val expr =
Expand All @@ -199,7 +200,7 @@ class ImportResolutionSuite extends FunSuite {
val cache = InMemoryCache()

val expected = parse("let x = 2 in x")
val encoded = expected.alphaNormalize.normalize.getEncodedBytes
val encoded = expected.normalize.alphaNormalize.getEncodedBytes
val hash = MessageDigest.getInstance("SHA-256").digest(encoded)

val expr = parse(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,9 @@ import cats.effect.{ContextShift, IO}
import java.nio.file.{Files, Paths}
import org.dhallj.core.Expr
import org.dhallj.core.binary.Decode.decode
import org.dhallj.imports.mini.Resolver
import org.dhallj.parser.DhallParser

import org.dhallj.imports.{ImportCache, ResolveImports}
import org.dhallj.imports.{ImportCache, Resolver}
import org.http4s.client._
import org.http4s.client.blaze._

Expand Down Expand Up @@ -59,7 +58,7 @@ trait CachedResolvingInput extends Input[Expr] {
implicit val cs: ContextShift[IO] = IO.contextShift(global)
BlazeClientBuilder[IO](global).resource.use { client =>
implicit val c: Client[IO] = client
ResolveImports(parsed)
Resolver.resolve[IO](parsed)
}.unsafeRunSync
}
}
Expand All @@ -76,7 +75,7 @@ trait ResolvingInput extends Input[Expr] {
implicit val cs: ContextShift[IO] = IO.contextShift(global)
BlazeClientBuilder[IO](global).resource.use { client =>
implicit val c: Client[IO] = client
ResolveImports(new ImportCache.NoopImportCache[IO], new ImportCache.NoopImportCache[IO])(parsed)
Resolver.resolve[IO](new ImportCache.NoopImportCache[IO], new ImportCache.NoopImportCache[IO])(parsed)
}.unsafeRunSync
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import java.nio.file.Files
import cats.effect.{ContextShift, IO}

import org.dhallj.core.Expr
import org.dhallj.imports.{ImportCache, ResolveImports}
import org.dhallj.imports.{ImportCache, Resolver}
import org.dhallj.parser.DhallParser

import org.http4s.client._
Expand All @@ -29,7 +29,7 @@ class ImportResolutionSuite(val base: String)
val cache = initializeCache
BlazeClientBuilder[IO](global).resource.use { client =>
implicit val c: Client[IO] = client
ResolveImports[IO](cache, new ImportCache.NoopImportCache[IO])(parsed)
Resolver.resolve[IO](cache, new ImportCache.NoopImportCache[IO])(parsed)
}.unsafeRunSync
}
}
Expand Down

0 comments on commit 73c8f16

Please sign in to comment.