summaryrefslogtreecommitdiff
path: root/dhall
diff options
context:
space:
mode:
Diffstat (limited to '')
m---------dhall-lang0
-rw-r--r--dhall/Cargo.toml2
-rw-r--r--dhall/build.rs89
-rw-r--r--dhall/src/error/mod.rs13
-rw-r--r--dhall/src/lib.rs8
-rw-r--r--dhall/src/semantics/nze/normalize.rs156
-rw-r--r--dhall/src/semantics/parse.rs23
-rw-r--r--dhall/src/semantics/resolve/env.rs30
-rw-r--r--dhall/src/semantics/resolve/hir.rs3
-rw-r--r--dhall/src/semantics/resolve/resolve.rs289
-rw-r--r--dhall/src/syntax/ast/expr.rs2
-rw-r--r--dhall/src/syntax/ast/import.rs10
-rw-r--r--dhall/src/syntax/ast/text.rs29
-rw-r--r--dhall/src/syntax/binary/decode.rs10
-rw-r--r--dhall/src/syntax/binary/encode.rs28
-rw-r--r--dhall/src/syntax/text/parser.rs18
-rw-r--r--dhall/src/syntax/text/printer.rs4
-rw-r--r--dhall/src/tests.rs10
-rw-r--r--dhall/tests/import/data/cycle.dhall1
-rw-r--r--dhall/tests/import/data/doesNotTypecheck.dhall1
-rw-r--r--dhall/tests/import/data/example.txt1
-rw-r--r--dhall/tests/import/data/fieldOrder/1.dhall1
-rw-r--r--dhall/tests/import/data/fieldOrder/2.dhall1
-rw-r--r--dhall/tests/import/data/importBoundary.dhall3
-rw-r--r--dhall/tests/import/data/nested.dhall1
-rw-r--r--dhall/tests/import/data/referentiallyOpaque.dhall18
-rw-r--r--dhall/tests/import/data/simple.dhall1
-rw-r--r--dhall/tests/import/data/simpleLocation.dhall1
-rw-r--r--dhall/tests/import/failure/alternativeEnv.txt1
-rw-r--r--dhall/tests/import/failure/alternativeEnvMissing.txt1
-rw-r--r--dhall/tests/import/failure/cycle.txt2
-rw-r--r--dhall/tests/import/failure/missing.txt1
-rw-r--r--dhall/tests/import/failure/referentiallyInsane.txt1
-rw-r--r--dhall/tests/import/failure/unit/EnvUnset.dhall1
-rw-r--r--dhall/tests/import/failure/unit/EnvUnset.txt1
-rw-r--r--dhall/tests/import/failure/unit/EnvUnsetAsText.dhall1
-rw-r--r--dhall/tests/import/failure/unit/EnvUnsetAsText.txt1
-rw-r--r--dhall/tests/import/success/unit/AlternativeChain1A.dhall1
-rw-r--r--dhall/tests/import/success/unit/AlternativeChain1B.dhall1
-rw-r--r--dhall/tests/import/success/unit/AlternativeChain2A.dhall1
-rw-r--r--dhall/tests/import/success/unit/AlternativeChain2B.dhall1
-rw-r--r--dhall/tests/import/success/unit/AlternativeEnvA.dhall1
-rw-r--r--dhall/tests/import/success/unit/AlternativeEnvB.dhall1
-rw-r--r--dhall/tests/import/success/unit/AlternativeHashMismatchA.dhall1
-rw-r--r--dhall/tests/import/success/unit/AlternativeHashMismatchB.dhall1
-rw-r--r--dhall/tests/import/success/unit/AlternativeImportErrorA.dhall1
-rw-r--r--dhall/tests/import/success/unit/AlternativeImportErrorB.dhall1
-rw-r--r--dhall/tests/import/success/unit/AlternativeNestedImportErrorA.dhall1
-rw-r--r--dhall/tests/import/success/unit/AlternativeNestedImportErrorB.dhall1
-rw-r--r--dhall/tests/import/success/unit/AlternativeNoError1A.dhall1
-rw-r--r--dhall/tests/import/success/unit/AlternativeNoError1B.dhall1
-rw-r--r--dhall/tests/import/success/unit/AlternativeNoError2A.dhall1
-rw-r--r--dhall/tests/import/success/unit/AlternativeNoError2B.dhall1
-rw-r--r--dhall/tests/import/success/unit/AlternativeNoError3A.dhall1
-rw-r--r--dhall/tests/import/success/unit/AlternativeNoError3B.dhall1
-rw-r--r--dhall/tests/import/success/unit/AlternativeParseErrorA.dhall1
-rw-r--r--dhall/tests/import/success/unit/AlternativeParseErrorB.dhall1
-rw-r--r--dhall/tests/import/success/unit/AlternativeSubExprA.dhall1
-rw-r--r--dhall/tests/import/success/unit/AlternativeSubExprB.dhall1
-rw-r--r--dhall/tests/import/success/unit/AlternativeTypeErrorA.dhall1
-rw-r--r--dhall/tests/import/success/unit/AlternativeTypeErrorB.dhall1
-rw-r--r--dhall/tests/import/success/unit/AsTextA.dhall1
-rw-r--r--dhall/tests/import/success/unit/AsTextB.dhall3
-rw-r--r--dhall/tests/import/success/unit/EnvSetA.dhall1
-rw-r--r--dhall/tests/import/success/unit/EnvSetAsTextA.dhall1
-rw-r--r--dhall/tests/import/success/unit/EnvSetAsTextB.dhall1
-rw-r--r--dhall/tests/import/success/unit/EnvSetB.dhall1
-rw-r--r--dhall/tests/import/success/unit/NormalizeA.dhall1
-rw-r--r--dhall/tests/import/success/unit/NormalizeB.dhall1
-rw-r--r--dhall/tests/import/success/unit/RemoteAsTextA.dhall1
-rw-r--r--dhall/tests/import/success/unit/RemoteAsTextB.dhall3
-rw-r--r--dhall/tests/import/success/unit/SimpleA.dhall1
-rw-r--r--dhall/tests/import/success/unit/SimpleB.dhall1
-rw-r--r--dhall/tests/import/success/unit/SimpleRemoteA.dhall1
-rw-r--r--dhall/tests/import/success/unit/SimpleRemoteB.dhall1
-rw-r--r--dhall/tests/import/success/unit/asLocation/AbsoluteA.dhall1
-rw-r--r--dhall/tests/import/success/unit/asLocation/AbsoluteB.dhall2
-rw-r--r--dhall/tests/import/success/unit/asLocation/Canonicalize1A.dhall1
-rw-r--r--dhall/tests/import/success/unit/asLocation/Canonicalize1B.dhall2
-rw-r--r--dhall/tests/import/success/unit/asLocation/Canonicalize2A.dhall1
-rw-r--r--dhall/tests/import/success/unit/asLocation/Canonicalize2B.dhall2
-rw-r--r--dhall/tests/import/success/unit/asLocation/Canonicalize3A.dhall1
-rw-r--r--dhall/tests/import/success/unit/asLocation/Canonicalize3B.dhall2
-rw-r--r--dhall/tests/import/success/unit/asLocation/Canonicalize4A.dhall1
-rw-r--r--dhall/tests/import/success/unit/asLocation/Canonicalize4B.dhall2
-rw-r--r--dhall/tests/import/success/unit/asLocation/Canonicalize5A.dhall1
-rw-r--r--dhall/tests/import/success/unit/asLocation/Canonicalize5B.dhall2
-rw-r--r--dhall/tests/import/success/unit/asLocation/Chain1A.dhall1
-rw-r--r--dhall/tests/import/success/unit/asLocation/Chain1B.dhall2
-rw-r--r--dhall/tests/import/success/unit/asLocation/Chain2A.dhall1
-rw-r--r--dhall/tests/import/success/unit/asLocation/Chain2B.dhall2
-rw-r--r--dhall/tests/import/success/unit/asLocation/Chain3A.dhall1
-rw-r--r--dhall/tests/import/success/unit/asLocation/Chain3B.dhall2
-rw-r--r--dhall/tests/import/success/unit/asLocation/DontTryResolvingA.dhall1
-rw-r--r--dhall/tests/import/success/unit/asLocation/DontTryResolvingB.dhall1
-rw-r--r--dhall/tests/import/success/unit/asLocation/EnvA.dhall1
-rw-r--r--dhall/tests/import/success/unit/asLocation/EnvB.dhall2
-rw-r--r--dhall/tests/import/success/unit/asLocation/HashA.dhall1
-rw-r--r--dhall/tests/import/success/unit/asLocation/HashB.dhall2
-rw-r--r--dhall/tests/import/success/unit/asLocation/HomeA.dhall1
-rw-r--r--dhall/tests/import/success/unit/asLocation/HomeB.dhall2
-rw-r--r--dhall/tests/import/success/unit/asLocation/MissingA.dhall1
-rw-r--r--dhall/tests/import/success/unit/asLocation/MissingB.dhall1
-rw-r--r--dhall/tests/import/success/unit/asLocation/Relative1A.dhall1
-rw-r--r--dhall/tests/import/success/unit/asLocation/Relative1B.dhall2
-rw-r--r--dhall/tests/import/success/unit/asLocation/Relative2A.dhall1
-rw-r--r--dhall/tests/import/success/unit/asLocation/Relative2B.dhall2
-rw-r--r--dhall/tests/import/success/unit/asLocation/RemoteA.dhall1
-rw-r--r--dhall/tests/import/success/unit/asLocation/RemoteB.dhall2
-rw-r--r--dhall/tests/import/success/unit/asLocation/RemoteCanonicalize1A.dhall1
-rw-r--r--dhall/tests/import/success/unit/asLocation/RemoteCanonicalize1B.dhall2
-rw-r--r--dhall/tests/import/success/unit/asLocation/RemoteCanonicalize2A.dhall1
-rw-r--r--dhall/tests/import/success/unit/asLocation/RemoteCanonicalize2B.dhall2
-rw-r--r--dhall/tests/import/success/unit/asLocation/RemoteCanonicalize3A.dhall1
-rw-r--r--dhall/tests/import/success/unit/asLocation/RemoteCanonicalize3B.dhall2
-rw-r--r--dhall/tests/import/success/unit/asLocation/RemoteCanonicalize4A.dhall1
-rw-r--r--dhall/tests/import/success/unit/asLocation/RemoteCanonicalize4B.dhall2
-rw-r--r--dhall/tests/import/success/unit/asLocation/RemoteChain1A.dhall1
-rw-r--r--dhall/tests/import/success/unit/asLocation/RemoteChain1B.dhall2
-rw-r--r--dhall/tests/import/success/unit/asLocation/RemoteChain2A.dhall1
-rw-r--r--dhall/tests/import/success/unit/asLocation/RemoteChain2B.dhall2
-rw-r--r--dhall/tests/import/success/unit/asLocation/RemoteChain3A.dhall1
-rw-r--r--dhall/tests/import/success/unit/asLocation/RemoteChain3B.dhall2
-rw-r--r--dhall/tests/normalization/success/regression/NaturalFoldExtraArgA.dhall1
-rw-r--r--dhall/tests/normalization/success/regression/NaturalFoldExtraArgB.dhall1
-rw-r--r--dhall/tests/normalization/success/regression/TrickyBinderIdentityA.dhall1
-rw-r--r--dhall/tests/normalization/success/regression/TrickyBinderIdentityB.dhall1
-rw-r--r--dhall/tests/normalization/success/unit/TextLitNested1A.dhall1
-rw-r--r--dhall/tests/normalization/success/unit/TextLitNested1B.dhall1
-rw-r--r--dhall/tests/normalization/success/unit/TextLitNested2A.dhall1
-rw-r--r--dhall/tests/normalization/success/unit/TextLitNested2B.dhall1
-rw-r--r--dhall/tests/normalization/success/unit/TextLitNested3A.dhall1
-rw-r--r--dhall/tests/normalization/success/unit/TextLitNested3B.dhall1
-rw-r--r--dhall/tests/normalization/success/unit/TextShowEmptyA.dhall1
-rw-r--r--dhall/tests/normalization/success/unit/TextShowEmptyB.dhall1
-rw-r--r--dhall/tests/parser/failure/assertBinding.txt6
-rw-r--r--dhall/tests/parser/failure/spacing/AssertNoSpace.txt6
-rw-r--r--dhall/tests/parser/failure/unit/AssertNoAnnotation.dhall1
-rw-r--r--dhall/tests/parser/failure/unit/AssertNoAnnotation.txt6
-rw-r--r--dhall/tests/parser/success/unit/EmptyRecordLiteralA.dhall1
-rw-r--r--dhall/tests/parser/success/unit/EmptyRecordLiteralB.dhallb1
-rw-r--r--dhall/tests/parser/success/unit/EmptyRecordLiteralB.diag1
-rw-r--r--dhall/tests/parser/success/unit/LetAnnotA.dhall1
-rw-r--r--dhall/tests/parser/success/unit/LetAnnotB.dhallbbin0 -> 17 bytes
-rw-r--r--dhall/tests/parser/success/unit/LetAnnotB.diag1
-rw-r--r--dhall/tests/parser/success/unit/LetNoAnnotA.dhall1
-rw-r--r--dhall/tests/parser/success/unit/LetNoAnnotB.dhallbbin0 -> 14 bytes
-rw-r--r--dhall/tests/parser/success/unit/LetNoAnnotB.diag1
-rw-r--r--dhall/tests/parser/success/unit/ToMapA.dhall1
-rw-r--r--dhall/tests/parser/success/unit/ToMapAnnotA.dhall1
-rw-r--r--dhall/tests/parser/success/unit/ToMapAnnotB.dhallbbin0 -> 11 bytes
-rw-r--r--dhall/tests/parser/success/unit/ToMapAnnotB.diag1
-rw-r--r--dhall/tests/parser/success/unit/ToMapB.dhallbbin0 -> 7 bytes
-rw-r--r--dhall/tests/parser/success/unit/ToMapB.diag1
-rw-r--r--dhall/tests/parser/success/unit/VariableQuotedWithSpaceA.dhall1
-rw-r--r--dhall/tests/parser/success/unit/VariableQuotedWithSpaceB.dhallbbin0 -> 6 bytes
-rw-r--r--dhall/tests/parser/success/unit/VariableQuotedWithSpaceB.diag1
-rw-r--r--dhall/tests/type-inference/failure/unit/FunctionTypeOutputTypeNotAType.dhall1
-rw-r--r--dhall/tests/type-inference/failure/unit/FunctionTypeOutputTypeNotAType.txt7
-rw-r--r--dhall/tests/type-inference/failure/unit/LetInSort.dhall1
-rw-r--r--dhall/tests/type-inference/failure/unit/LetInSort.txt6
-rw-r--r--dhall/tests/type-inference/failure/unit/MergeBool.dhall1
-rw-r--r--dhall/tests/type-inference/failure/unit/MergeBool.txt6
-rw-r--r--dhall/tests/type-inference/failure/unit/NestedAnnotInnerWrong.dhall1
-rw-r--r--dhall/tests/type-inference/failure/unit/NestedAnnotInnerWrong.txt6
-rw-r--r--dhall/tests/type-inference/failure/unit/NestedAnnotOuterWrong.dhall1
-rw-r--r--dhall/tests/type-inference/failure/unit/NestedAnnotOuterWrong.txt6
-rw-r--r--dhall/tests/type-inference/success/CacheImportsA.dhall6
-rw-r--r--dhall/tests/type-inference/success/CacheImportsB.dhall1
-rw-r--r--dhall/tests/type-inference/success/CacheImportsCanonicalizeA.dhall5
-rw-r--r--dhall/tests/type-inference/success/CacheImportsCanonicalizeB.dhall1
-rw-r--r--dhall/tests/type-inference/success/regression/LambdaInLetScoping1A.dhall1
-rw-r--r--dhall/tests/type-inference/success/regression/LambdaInLetScoping1B.dhall1
-rw-r--r--dhall/tests/type-inference/success/regression/LambdaInLetScoping2A.dhall1
-rw-r--r--dhall/tests/type-inference/success/regression/LambdaInLetScoping2B.dhall1
-rw-r--r--dhall/tests/type-inference/success/regression/RecursiveRecordTypeMergeTripleCollisionA.dhall1
-rw-r--r--dhall/tests/type-inference/success/regression/RecursiveRecordTypeMergeTripleCollisionB.dhall1
-rw-r--r--dhall/tests/type-inference/success/regression/TodoA.dhall1
-rw-r--r--dhall/tests/type-inference/success/regression/TodoB.dhall1
179 files changed, 703 insertions, 273 deletions
diff --git a/dhall-lang b/dhall-lang
-Subproject 68c8aa875801355a319261c87b547b9a017df3c
+Subproject 1a20024421d4e0574e7d9c85a7b0e751b0534dc
diff --git a/dhall/Cargo.toml b/dhall/Cargo.toml
index 4d9595a..90374b6 100644
--- a/dhall/Cargo.toml
+++ b/dhall/Cargo.toml
@@ -18,9 +18,11 @@ once_cell = "1.3.1"
percent-encoding = "2.1.0"
pest = "2.1"
pest_consume = "1.0"
+reqwest = { version = "0.10.3", features = ["blocking"] }
serde = "1.0"
serde_cbor = "0.9.0"
smallvec = "1.0.0"
+url = "2.1.1"
[dev-dependencies]
pretty_assertions = "0.6.1"
diff --git a/dhall/build.rs b/dhall/build.rs
index d9bceeb..4b6e52b 100644
--- a/dhall/build.rs
+++ b/dhall/build.rs
@@ -77,8 +77,10 @@ struct TestFeature {
directory: &'static str,
/// Relevant variant of `dhall::tests::Test`
variant: &'static str,
+ /// Given a file name, whether to only include it in release tests
+ too_slow_path: Box<dyn FnMut(&str) -> bool>,
/// Given a file name, whether to exclude it
- path_filter: Box<dyn FnMut(&str) -> bool>,
+ exclude_path: Box<dyn FnMut(&str) -> bool>,
/// Type of the input file
input_type: FileType,
/// Type of the output file, if any
@@ -98,9 +100,12 @@ fn make_test_module(
for (name, path) in
dhall_files_in_dir(&tests_dir, take_ab_suffix, feature.input_type)
{
- if (feature.path_filter)(&path) {
+ if (feature.exclude_path)(&path) {
continue;
}
+ if (feature.too_slow_path)(&path) {
+ writeln!(w, "#[cfg(not(debug_assertions))]")?;
+ }
let path = tests_dir.join(path);
let path = path.to_string_lossy();
let test = match feature.output_type {
@@ -152,10 +157,9 @@ fn generate_tests() -> std::io::Result<()> {
module_name: "parser_success",
directory: "parser/success/",
variant: "ParserSuccess",
- path_filter: Box::new(|path: &str| {
+ too_slow_path: Box::new(|path: &str| path == "largeExpression"),
+ exclude_path: Box::new(|path: &str| {
false
- // Too slow in debug mode
- || path == "largeExpression"
// Pretty sure the test is incorrect
|| path == "unit/import/urls/quotedPathFakeUrlEncode"
// TODO: RFC3986 URLs
@@ -171,7 +175,8 @@ fn generate_tests() -> std::io::Result<()> {
module_name: "parser_failure",
directory: "parser/failure/",
variant: "ParserFailure",
- path_filter: Box::new(|_path: &str| false),
+ too_slow_path: Box::new(|_path: &str| false),
+ exclude_path: Box::new(|_path: &str| false),
input_type: FileType::Text,
output_type: Some(FileType::UI),
},
@@ -179,10 +184,9 @@ fn generate_tests() -> std::io::Result<()> {
module_name: "printer",
directory: "parser/success/",
variant: "Printer",
- path_filter: Box::new(|path: &str| {
+ too_slow_path: Box::new(|path: &str| path == "largeExpression"),
+ exclude_path: Box::new(|path: &str| {
false
- // Too slow in debug mode
- || path == "largeExpression"
// TODO: RFC3986 URLs
|| path == "unit/import/urls/emptyPath0"
|| path == "unit/import/urls/emptyPath1"
@@ -196,10 +200,9 @@ fn generate_tests() -> std::io::Result<()> {
module_name: "binary_encoding",
directory: "parser/success/",
variant: "BinaryEncoding",
- path_filter: Box::new(|path: &str| {
+ too_slow_path: Box::new(|path: &str| path == "largeExpression"),
+ exclude_path: Box::new(|path: &str| {
false
- // Too slow in debug mode
- || path == "largeExpression"
// Pretty sure the test is incorrect
|| path == "unit/import/urls/quotedPathFakeUrlEncode"
// See https://github.com/pyfisch/cbor/issues/109
@@ -219,7 +222,8 @@ fn generate_tests() -> std::io::Result<()> {
module_name: "binary_decoding_success",
directory: "binary-decode/success/",
variant: "BinaryDecodingSuccess",
- path_filter: Box::new(|path: &str| {
+ too_slow_path: Box::new(|_path: &str| false),
+ exclude_path: Box::new(|path: &str| {
false
// We don't support bignums
|| path == "unit/IntegerBigNegative"
@@ -233,7 +237,8 @@ fn generate_tests() -> std::io::Result<()> {
module_name: "binary_decoding_failure",
directory: "binary-decode/failure/",
variant: "BinaryDecodingFailure",
- path_filter: Box::new(|_path: &str| false),
+ too_slow_path: Box::new(|_path: &str| false),
+ exclude_path: Box::new(|_path: &str| false),
input_type: FileType::Binary,
output_type: Some(FileType::UI),
},
@@ -241,15 +246,19 @@ fn generate_tests() -> std::io::Result<()> {
module_name: "import_success",
directory: "import/success/",
variant: "ImportSuccess",
- path_filter: Box::new(|path: &str| {
+ too_slow_path: Box::new(|_path: &str| false),
+ exclude_path: Box::new(|path: &str| {
false
- || path == "alternativeEnvNatural"
- || path == "alternativeEnvSimple"
+ // TODO: import hash
|| path == "alternativeHashMismatch"
+ || path == "hashFromCache"
+ || path == "unit/AlternativeHashMismatch"
+ // TODO: This test is wrong
|| path == "asLocation"
- || path == "asText"
+ // TODO: the standard does not respect https://tools.ietf.org/html/rfc3986#section-5.2
+ || path == "unit/asLocation/RemoteCanonicalize4"
+ // TODO: import headers
|| path == "customHeaders"
- || path == "hashFromCache"
|| path == "headerForwarding"
|| path == "noHeaderForwarding"
}),
@@ -260,13 +269,12 @@ fn generate_tests() -> std::io::Result<()> {
module_name: "import_failure",
directory: "import/failure/",
variant: "ImportFailure",
- path_filter: Box::new(|path: &str| {
+ too_slow_path: Box::new(|_path: &str| false),
+ exclude_path: Box::new(|path: &str| {
false
- || path == "alternativeEnv"
- || path == "alternativeEnvMissing"
+ // TODO: import hash
|| path == "hashMismatch"
- || path == "missing"
- || path == "referentiallyInsane"
+ // TODO: import headers
|| path == "customHeadersUsingBoundVariable"
}),
input_type: FileType::Text,
@@ -276,25 +284,18 @@ fn generate_tests() -> std::io::Result<()> {
module_name: "beta_normalize",
directory: "normalization/success/",
variant: "Normalization",
- path_filter: Box::new(|path: &str| {
- // We don't support bignums
- path == "simple/integerToDouble"
- // Too slow
- || path == "remoteSystems"
+ too_slow_path: Box::new(|path: &str| path == "remoteSystems"),
+ exclude_path: Box::new(|path: &str| {
+ false
+ // We don't support bignums
+ || path == "simple/integerToDouble"
// TODO: fix Double/show
|| path == "prelude/JSON/number/1"
// TODO: doesn't typecheck
|| path == "unit/RightBiasedRecordMergeWithinRecordProjection"
|| path == "unit/Sort"
- // // TODO: Further record simplifications
- || path == "simplifications/rightBiasedMergeWithinRecordProjectionWithinFieldSelection0"
- || path == "simplifications/rightBiasedMergeWithinRecordProjectionWithinFieldSelection1"
- || path == "simplifications/rightBiasedMergeWithinRecursiveRecordMergeWithinFieldselection"
+ // TODO: Further record simplifications
|| path == "simplifications/issue661"
- || path == "unit/RecursiveRecordMergeWithinFieldSelection0"
- || path == "unit/RecursiveRecordMergeWithinFieldSelection1"
- || path == "unit/RecursiveRecordMergeWithinFieldSelection2"
- || path == "unit/RecursiveRecordMergeWithinFieldSelection3"
}),
input_type: FileType::Text,
output_type: Some(FileType::Text),
@@ -303,8 +304,9 @@ fn generate_tests() -> std::io::Result<()> {
module_name: "alpha_normalize",
directory: "alpha-normalization/success/",
variant: "AlphaNormalization",
- path_filter: Box::new(|path: &str| {
- // This test doesn't typecheck
+ too_slow_path: Box::new(|_path: &str| false),
+ exclude_path: Box::new(|path: &str| {
+ // This test is designed to not typecheck
path == "unit/FunctionNestedBindingXXFree"
}),
input_type: FileType::Text,
@@ -314,9 +316,11 @@ fn generate_tests() -> std::io::Result<()> {
module_name: "type_inference_success",
directory: "type-inference/success/",
variant: "TypeInferenceSuccess",
- path_filter: Box::new(|path: &str| {
+ too_slow_path: Box::new(|_path: &str| false),
+ exclude_path: Box::new(|path: &str| {
false
- // Too slow
+ // Too slow, but also not all features implemented
+ // For now needs support for hashed imports
|| path == "prelude"
}),
input_type: FileType::Text,
@@ -326,7 +330,8 @@ fn generate_tests() -> std::io::Result<()> {
module_name: "type_inference_failure",
directory: "type-inference/failure/",
variant: "TypeInferenceFailure",
- path_filter: Box::new(|path: &str| {
+ too_slow_path: Box::new(|_path: &str| false),
+ exclude_path: Box::new(|path: &str| {
false
// TODO: enable free variable checking
|| path == "unit/MergeHandlerFreeVar"
diff --git a/dhall/src/error/mod.rs b/dhall/src/error/mod.rs
index 8829d47..e28b98b 100644
--- a/dhall/src/error/mod.rs
+++ b/dhall/src/error/mod.rs
@@ -1,6 +1,6 @@
use std::io::Error as IOError;
-use crate::semantics::resolve::ImportStack;
+use crate::semantics::resolve::{ImportLocation, ImportStack};
use crate::syntax::{Import, ParseError};
mod builder;
@@ -26,8 +26,12 @@ pub(crate) enum ErrorKind {
#[derive(Debug)]
pub(crate) enum ImportError {
+ Missing,
+ MissingEnvVar,
+ SanityCheck,
UnexpectedImport(Import<()>),
- ImportCycle(ImportStack, Import<()>),
+ ImportCycle(ImportStack, ImportLocation),
+ Url(url::ParseError),
}
#[derive(Debug)]
@@ -109,6 +113,11 @@ impl From<ParseError> for Error {
ErrorKind::Parse(err).into()
}
}
+impl From<url::ParseError> for Error {
+ fn from(err: url::ParseError) -> Error {
+ ErrorKind::Resolve(ImportError::Url(err)).into()
+ }
+}
impl From<DecodeError> for Error {
fn from(err: DecodeError) -> Error {
ErrorKind::Decode(err).into()
diff --git a/dhall/src/lib.rs b/dhall/src/lib.rs
index 34d7bc3..d68ad6b 100644
--- a/dhall/src/lib.rs
+++ b/dhall/src/lib.rs
@@ -17,11 +17,12 @@ pub mod syntax;
use std::fmt::Display;
use std::path::Path;
+use url::Url;
use crate::error::{EncodeError, Error, TypeError};
use crate::semantics::parse;
use crate::semantics::resolve;
-use crate::semantics::resolve::ImportRoot;
+use crate::semantics::resolve::ImportLocation;
use crate::semantics::{
typecheck, typecheck_with, Hir, Nir, NirKind, Tir, Type,
};
@@ -34,7 +35,7 @@ pub type ResolvedExpr = Expr;
pub type NormalizedExpr = Expr;
#[derive(Debug, Clone)]
-pub struct Parsed(ParsedExpr, ImportRoot);
+pub struct Parsed(ParsedExpr, ImportLocation);
/// An expression where all imports have been resolved
///
@@ -66,6 +67,9 @@ impl Parsed {
pub fn parse_file(f: &Path) -> Result<Parsed, Error> {
parse::parse_file(f)
}
+ pub fn parse_remote(url: Url) -> Result<Parsed, Error> {
+ parse::parse_remote(url)
+ }
pub fn parse_str(s: &str) -> Result<Parsed, Error> {
parse::parse_str(s)
}
diff --git a/dhall/src/semantics/nze/normalize.rs b/dhall/src/semantics/nze/normalize.rs
index dedd659..27862ee 100644
--- a/dhall/src/semantics/nze/normalize.rs
+++ b/dhall/src/semantics/nze/normalize.rs
@@ -233,7 +233,7 @@ pub(crate) fn normalize_one_layer(expr: ExprKind<Nir>, env: &NzEnv) -> NirKind {
ExprKind::Builtin(b) => Ret::Nir(Nir::from_builtin_env(b, env)),
ExprKind::Assert(_) => Ret::Expr(expr),
ExprKind::App(v, a) => Ret::Nir(v.app(a)),
- ExprKind::Lit(l) => Ret::NirKind(Lit(l.clone())),
+ ExprKind::Lit(l) => Ret::NirKind(Lit(l)),
ExprKind::SomeLit(e) => Ret::NirKind(NEOptionalLit(e)),
ExprKind::EmptyListLit(t) => {
let arg = match t.kind() {
@@ -286,23 +286,6 @@ pub(crate) fn normalize_one_layer(expr: ExprKind<Nir>, env: &NzEnv) -> NirKind {
None => Ret::Expr(expr),
},
- ExprKind::Projection(_, ref ls) if ls.is_empty() => {
- Ret::NirKind(RecordLit(HashMap::new()))
- }
- ExprKind::Projection(ref v, ref ls) => match v.kind() {
- RecordLit(kvs) => Ret::NirKind(RecordLit(
- ls.iter()
- .filter_map(|l| kvs.get(l).map(|x| (l.clone(), x.clone())))
- .collect(),
- )),
- PartialExpr(ExprKind::Projection(v2, _)) => {
- return normalize_one_layer(
- ExprKind::Projection(v2.clone(), ls.clone()),
- env,
- )
- }
- _ => Ret::Expr(expr),
- },
ExprKind::Field(ref v, ref l) => match v.kind() {
RecordLit(kvs) => match kvs.get(l) {
Some(r) => Ret::Nir(r.clone()),
@@ -311,6 +294,12 @@ pub(crate) fn normalize_one_layer(expr: ExprKind<Nir>, env: &NzEnv) -> NirKind {
UnionType(kts) => {
Ret::NirKind(UnionConstructor(l.clone(), kts.clone()))
}
+ PartialExpr(ExprKind::Projection(x, _)) => {
+ return normalize_one_layer(
+ ExprKind::Field(x.clone(), l.clone()),
+ env,
+ )
+ }
PartialExpr(ExprKind::BinOp(
BinOp::RightBiasedRecordMerge,
x,
@@ -329,11 +318,11 @@ pub(crate) fn normalize_one_layer(expr: ExprKind<Nir>, env: &NzEnv) -> NirKind {
Some(r) => Ret::Expr(ExprKind::Field(
Nir::from_kind(PartialExpr(ExprKind::BinOp(
BinOp::RightBiasedRecordMerge,
- Nir::from_kind(RecordLit({
- let mut kvs = HashMap::new();
- kvs.insert(l.clone(), r.clone());
- kvs
- })),
+ Nir::from_kind(RecordLit(
+ Some((l.clone(), r.clone()))
+ .into_iter()
+ .collect(),
+ )),
y.clone(),
))),
l.clone(),
@@ -347,66 +336,81 @@ pub(crate) fn normalize_one_layer(expr: ExprKind<Nir>, env: &NzEnv) -> NirKind {
},
_ => Ret::Expr(expr),
},
- PartialExpr(ExprKind::BinOp(
- BinOp::RecursiveRecordTypeMerge,
- x,
- y,
- )) => match (x.kind(), y.kind()) {
- (RecordLit(kvs), _) => match kvs.get(l) {
- Some(_) => Ret::Expr(expr),
- None => {
- return normalize_one_layer(
- ExprKind::Field(y.clone(), l.clone()),
- env,
- )
- }
- },
- (_, RecordLit(kvs)) => match kvs.get(l) {
- Some(_) => Ret::Expr(expr),
- None => {
- return normalize_one_layer(
- ExprKind::Field(x.clone(), l.clone()),
- env,
- )
- }
- },
- _ => Ret::Expr(expr),
- },
+ PartialExpr(ExprKind::BinOp(BinOp::RecursiveRecordMerge, x, y)) => {
+ match (x.kind(), y.kind()) {
+ (RecordLit(kvs), _) => match kvs.get(l) {
+ Some(r) => Ret::Expr(ExprKind::Field(
+ Nir::from_kind(PartialExpr(ExprKind::BinOp(
+ BinOp::RecursiveRecordMerge,
+ Nir::from_kind(RecordLit(
+ Some((l.clone(), r.clone()))
+ .into_iter()
+ .collect(),
+ )),
+ y.clone(),
+ ))),
+ l.clone(),
+ )),
+ None => {
+ return normalize_one_layer(
+ ExprKind::Field(y.clone(), l.clone()),
+ env,
+ )
+ }
+ },
+ (_, RecordLit(kvs)) => match kvs.get(l) {
+ Some(r) => Ret::Expr(ExprKind::Field(
+ Nir::from_kind(PartialExpr(ExprKind::BinOp(
+ BinOp::RecursiveRecordMerge,
+ x.clone(),
+ Nir::from_kind(RecordLit(
+ Some((l.clone(), r.clone()))
+ .into_iter()
+ .collect(),
+ )),
+ ))),
+ l.clone(),
+ )),
+ None => {
+ return normalize_one_layer(
+ ExprKind::Field(x.clone(), l.clone()),
+ env,
+ )
+ }
+ },
+ _ => Ret::Expr(expr),
+ }
+ }
+ _ => Ret::Expr(expr),
+ },
+ ExprKind::Projection(_, ref ls) if ls.is_empty() => {
+ Ret::NirKind(RecordLit(HashMap::new()))
+ }
+ ExprKind::Projection(ref v, ref ls) => match v.kind() {
+ RecordLit(kvs) => Ret::NirKind(RecordLit(
+ ls.iter()
+ .filter_map(|l| kvs.get(l).map(|x| (l.clone(), x.clone())))
+ .collect(),
+ )),
PartialExpr(ExprKind::Projection(v2, _)) => {
return normalize_one_layer(
- ExprKind::Field(v2.clone(), l.clone()),
+ ExprKind::Projection(v2.clone(), ls.clone()),
env,
)
}
_ => Ret::Expr(expr),
},
-
- ExprKind::ProjectionByExpr(ref v, ref t) => match dbg!(v).kind() {
- RecordLit(kvs) => match dbg!(t).kind() {
- RecordType(kts) => Ret::NirKind(RecordLit(
- kts.iter()
- .filter_map(|(l, _)| {
- kvs.get(l).map(|x| (l.clone(), x.clone()))
- })
- .collect(),
- )),
- _ => Ret::Expr(expr),
- },
- _ => match dbg!(t).kind() {
- RecordType(kts) => {
- use crate::syntax::map::DupTreeSet;
- use std::iter::FromIterator;
-
- let ts = DupTreeSet::from_iter(
- kts.iter().map(|(l, _)| l.clone()),
- );
- return normalize_one_layer(
- ExprKind::Projection(v.clone(), ts),
- env,
- );
- }
- _ => Ret::Expr(expr),
- },
+ ExprKind::ProjectionByExpr(ref v, ref t) => match t.kind() {
+ RecordType(kts) => {
+ return normalize_one_layer(
+ ExprKind::Projection(
+ v.clone(),
+ kts.keys().cloned().collect(),
+ ),
+ env,
+ )
+ }
+ _ => Ret::Expr(expr),
},
ExprKind::Merge(ref handlers, ref variant, _) => {
diff --git a/dhall/src/semantics/parse.rs b/dhall/src/semantics/parse.rs
index ee35536..45860d0 100644
--- a/dhall/src/semantics/parse.rs
+++ b/dhall/src/semantics/parse.rs
@@ -1,30 +1,37 @@
use std::fs::File;
use std::io::Read;
use std::path::Path;
+use url::Url;
use crate::error::Error;
-use crate::semantics::resolve::ImportRoot;
+use crate::semantics::resolve::ImportLocation;
use crate::syntax::binary;
use crate::syntax::parse_expr;
use crate::Parsed;
pub(crate) fn parse_file(f: &Path) -> Result<Parsed, Error> {
- let mut buffer = String::new();
- File::open(f)?.read_to_string(&mut buffer)?;
- let expr = parse_expr(&*buffer)?;
- let root = ImportRoot::LocalDir(f.parent().unwrap().to_owned());
+ let text = std::fs::read_to_string(f)?;
+ let expr = parse_expr(&text)?;
+ let root = ImportLocation::Local(f.to_owned());
+ Ok(Parsed(expr, root))
+}
+
+pub(crate) fn parse_remote(url: Url) -> Result<Parsed, Error> {
+ let body = reqwest::blocking::get(url.clone()).unwrap().text().unwrap();
+ let expr = parse_expr(&body)?;
+ let root = ImportLocation::Remote(url);
Ok(Parsed(expr, root))
}
pub(crate) fn parse_str(s: &str) -> Result<Parsed, Error> {
let expr = parse_expr(s)?;
- let root = ImportRoot::LocalDir(std::env::current_dir()?);
+ let root = ImportLocation::Missing;
Ok(Parsed(expr, root))
}
pub(crate) fn parse_binary(data: &[u8]) -> Result<Parsed, Error> {
let expr = binary::decode(data)?;
- let root = ImportRoot::LocalDir(std::env::current_dir()?);
+ let root = ImportLocation::Missing;
Ok(Parsed(expr, root))
}
@@ -32,6 +39,6 @@ pub(crate) fn parse_binary_file(f: &Path) -> Result<Parsed, Error> {
let mut buffer = Vec::new();
File::open(f)?.read_to_end(&mut buffer)?;
let expr = binary::decode(&buffer)?;
- let root = ImportRoot::LocalDir(f.parent().unwrap().to_owned());
+ let root = ImportLocation::Local(f.to_owned());
Ok(Parsed(expr, root))
}
diff --git a/dhall/src/semantics/resolve/env.rs b/dhall/src/semantics/resolve/env.rs
index 43676cc..5a7f139 100644
--- a/dhall/src/semantics/resolve/env.rs
+++ b/dhall/src/semantics/resolve/env.rs
@@ -1,7 +1,7 @@
use std::collections::HashMap;
use crate::error::{Error, ImportError};
-use crate::semantics::{AlphaVar, Import, TypedHir, VarEnv};
+use crate::semantics::{AlphaVar, ImportLocation, TypedHir, VarEnv};
use crate::syntax::{Label, V};
/// Environment for resolving names.
@@ -10,8 +10,8 @@ pub(crate) struct NameEnv {
names: Vec<Label>,
}
-pub(crate) type ImportCache = HashMap<Import, TypedHir>;
-pub(crate) type ImportStack = Vec<Import>;
+pub(crate) type ImportCache = HashMap<ImportLocation, TypedHir>;
+pub(crate) type ImportStack = Vec<ImportLocation>;
/// Environment for resolving imports
#[derive(Debug, Clone)]
@@ -74,28 +74,28 @@ impl ImportEnv {
pub fn handle_import(
&mut self,
- import: Import,
- mut do_resolve: impl FnMut(&mut Self, &Import) -> Result<TypedHir, Error>,
+ location: ImportLocation,
+ do_resolve: impl FnOnce(&mut Self) -> Result<TypedHir, Error>,
) -> Result<TypedHir, Error> {
- if self.stack.contains(&import) {
+ if self.stack.contains(&location) {
return Err(
- ImportError::ImportCycle(self.stack.clone(), import).into()
+ ImportError::ImportCycle(self.stack.clone(), location).into()
);
}
- Ok(match self.cache.get(&import) {
+ Ok(match self.cache.get(&location) {
Some(expr) => expr.clone(),
None => {
- // Push the current import on the stack
- self.stack.push(import.clone());
+ // Push the current location on the stack
+ self.stack.push(location);
// Resolve the import recursively
- let expr = do_resolve(self, &import)?;
+ let expr = do_resolve(self)?;
- // Remove import from the stack.
- self.stack.pop();
+ // Remove location from the stack.
+ let location = self.stack.pop().unwrap();
- // Add the import to the cache
- self.cache.insert(import, expr.clone());
+ // Add the resolved import to the cache
+ self.cache.insert(location, expr.clone());
expr
}
diff --git a/dhall/src/semantics/resolve/hir.rs b/dhall/src/semantics/resolve/hir.rs
index 2f3464a..317708a 100644
--- a/dhall/src/semantics/resolve/hir.rs
+++ b/dhall/src/semantics/resolve/hir.rs
@@ -72,6 +72,9 @@ impl Hir {
) -> Result<Tir<'hir>, TypeError> {
type_with(env, self, None)
}
+ pub fn typecheck_noenv<'hir>(&'hir self) -> Result<Tir<'hir>, TypeError> {
+ self.typecheck(&TyEnv::new())
+ }
/// Eval the Hir. It will actually get evaluated only as needed on demand.
pub fn eval(&self, env: impl Into<NzEnv>) -> Nir {
diff --git a/dhall/src/semantics/resolve/resolve.rs b/dhall/src/semantics/resolve/resolve.rs
index 82800ec..d29271d 100644
--- a/dhall/src/semantics/resolve/resolve.rs
+++ b/dhall/src/semantics/resolve/resolve.rs
@@ -1,11 +1,18 @@
+use itertools::Itertools;
use std::borrow::Cow;
-use std::path::{Path, PathBuf};
+use std::env;
+use std::path::PathBuf;
+use url::Url;
use crate::error::ErrorBuilder;
use crate::error::{Error, ImportError};
use crate::semantics::{mkerr, Hir, HirKind, ImportEnv, NameEnv, Type};
use crate::syntax;
-use crate::syntax::{BinOp, Expr, ExprKind, FilePath, ImportLocation, URL};
+use crate::syntax::map::DupTreeMap;
+use crate::syntax::{
+ BinOp, Builtin, Expr, ExprKind, FilePath, FilePrefix, ImportMode,
+ ImportTarget, Span, UnspannedExpr, URL,
+};
use crate::{Parsed, ParsedExpr, Resolved};
// TODO: evaluate import headers
@@ -14,42 +21,217 @@ pub(crate) type Import = syntax::Import<()>;
/// Owned Hir with a type. Different from Tir because the Hir is owned.
pub(crate) type TypedHir = (Hir, Type);
-/// A root from which to resolve relative imports.
-#[derive(Debug, Clone, PartialEq, Eq)]
-pub(crate) enum ImportRoot {
- LocalDir(PathBuf),
+/// The location of some data, usually some dhall code.
+#[derive(Debug, Clone, PartialEq, Eq, Hash)]
+pub(crate) enum ImportLocation {
+ /// Local file
+ Local(PathBuf),
+ /// Remote file
+ Remote(Url),
+ /// Environment variable
+ Env(String),
+ /// Data without a location
+ Missing,
+}
+
+impl ImportLocation {
+ /// Given an import pointing to `target` found in the current location, compute the next
+ /// location, or error if not allowed.
+ /// `sanity_check` indicates whether to check if that location is allowed to be referenced,
+ /// for example to prevent a remote file from reading an environment variable.
+ fn chain(
+ &self,
+ target: &ImportTarget<()>,
+ sanity_check: bool,
+ ) -> Result<ImportLocation, Error> {
+ Ok(match target {
+ ImportTarget::Local(prefix, path) => {
+ self.chain_local(prefix, path)?
+ }
+ ImportTarget::Remote(remote) => {
+ if sanity_check {
+ if let ImportLocation::Remote(..) = self {
+ // TODO: allow if CORS check passes
+ Err(ImportError::SanityCheck)?
+ }
+ }
+ let mut url = Url::parse(&format!(
+ "{}://{}",
+ remote.scheme, remote.authority
+ ))?;
+ url.set_path(&remote.path.file_path.iter().join("/"));
+ url.set_query(remote.query.as_ref().map(String::as_ref));
+ ImportLocation::Remote(url)
+ }
+ ImportTarget::Env(var_name) => {
+ if sanity_check {
+ if let ImportLocation::Remote(..) = self {
+ Err(ImportError::SanityCheck)?
+ }
+ }
+ ImportLocation::Env(var_name.clone())
+ }
+ ImportTarget::Missing => ImportLocation::Missing,
+ })
+ }
+
+ fn chain_local(
+ &self,
+ prefix: &FilePrefix,
+ path: &FilePath,
+ ) -> Result<ImportLocation, Error> {
+ Ok(match self {
+ ImportLocation::Local(..)
+ | ImportLocation::Env(..)
+ | ImportLocation::Missing => {
+ let dir = match self {
+ ImportLocation::Local(path) => {
+ path.parent().unwrap().to_owned()
+ }
+ ImportLocation::Env(..) | ImportLocation::Missing => {
+ std::env::current_dir()?
+ }
+ _ => unreachable!(),
+ };
+ let mut dir: Vec<String> = dir
+ .components()
+ .map(|component| {
+ component.as_os_str().to_string_lossy().into_owned()
+ })
+ .collect();
+ let root = match prefix {
+ FilePrefix::Here => dir,
+ FilePrefix::Parent => {
+ dir.push("..".to_string());
+ dir
+ }
+ FilePrefix::Absolute => vec![],
+ FilePrefix::Home => vec![],
+ };
+ let path: Vec<_> = root
+ .into_iter()
+ .chain(path.file_path.iter().cloned())
+ .collect();
+ let path =
+ (FilePath { file_path: path }).canonicalize().file_path;
+ let prefix = match prefix {
+ FilePrefix::Here | FilePrefix::Parent => ".",
+ FilePrefix::Absolute => "/",
+ FilePrefix::Home => "~",
+ };
+ let path =
+ Some(prefix.to_string()).into_iter().chain(path).collect();
+ ImportLocation::Local(path)
+ }
+ ImportLocation::Remote(url) => {
+ let mut url = url.clone();
+ match prefix {
+ FilePrefix::Here => {}
+ FilePrefix::Parent => {
+ url = url.join("..")?;
+ }
+ FilePrefix::Absolute => panic!("error"),
+ FilePrefix::Home => panic!("error"),
+ }
+ url = url.join(&path.file_path.join("/"))?;
+ ImportLocation::Remote(url)
+ }
+ })
+ }
+
+ fn fetch_dhall(self) -> Result<Parsed, Error> {
+ Ok(match self {
+ ImportLocation::Local(path) => Parsed::parse_file(&path)?,
+ ImportLocation::Remote(url) => Parsed::parse_remote(url)?,
+ ImportLocation::Env(var_name) => {
+ let val = match env::var(var_name) {
+ Ok(val) => val,
+ Err(_) => Err(ImportError::MissingEnvVar)?,
+ };
+ Parsed::parse_str(&val)?
+ }
+ ImportLocation::Missing => Err(ImportError::Missing)?,
+ })
+ }
+
+ fn fetch_text(self) -> Result<String, Error> {
+ Ok(match self {
+ ImportLocation::Local(path) => std::fs::read_to_string(&path)?,
+ ImportLocation::Remote(url) => {
+ reqwest::blocking::get(url).unwrap().text().unwrap()
+ }
+ ImportLocation::Env(var_name) => match env::var(var_name) {
+ Ok(val) => val,
+ Err(_) => Err(ImportError::MissingEnvVar)?,
+ },
+ ImportLocation::Missing => Err(ImportError::Missing)?,
+ })
+ }
+
+ fn into_location(self) -> Expr {
+ let (field_name, arg) = match self {
+ ImportLocation::Local(path) => {
+ ("Local", Some(path.to_string_lossy().into_owned()))
+ }
+ ImportLocation::Remote(url) => ("Remote", Some(url.into_string())),
+ ImportLocation::Env(name) => ("Environment", Some(name)),
+ ImportLocation::Missing => ("Missing", None),
+ };
+
+ let asloc_ty = make_aslocation_uniontype();
+ let expr = mkexpr(ExprKind::Field(asloc_ty, field_name.into()));
+ match arg {
+ Some(arg) => mkexpr(ExprKind::App(
+ expr,
+ mkexpr(ExprKind::TextLit(arg.into())),
+ )),
+ None => expr,
+ }
+ }
+}
+
+fn mkexpr(kind: UnspannedExpr) -> Expr {
+ Expr::new(kind, Span::Artificial)
+}
+
+fn make_aslocation_uniontype() -> Expr {
+ let text_type = mkexpr(ExprKind::Builtin(Builtin::Text));
+ let mut union = DupTreeMap::default();
+ union.insert("Local".into(), Some(text_type.clone()));
+ union.insert("Remote".into(), Some(text_type.clone()));
+ union.insert("Environment".into(), Some(text_type.clone()));
+ union.insert("Missing".into(), None);
+ mkexpr(ExprKind::UnionType(union))
}
fn resolve_one_import(
env: &mut ImportEnv,
import: &Import,
- root: &ImportRoot,
+ location: &ImportLocation,
) -> Result<TypedHir, Error> {
- use self::ImportRoot::*;
- use syntax::FilePrefix::*;
- use syntax::ImportLocation::*;
- let cwd = match root {
- LocalDir(cwd) => cwd,
- };
- match &import.location {
- Local(prefix, path) => {
- let path_buf: PathBuf = path.file_path.iter().collect();
- let path_buf = match prefix {
- // TODO: fail gracefully
- Parent => cwd.parent().unwrap().join(path_buf),
- Here => cwd.join(path_buf),
- _ => unimplemented!("{:?}", import),
- };
- Ok(load_import(env, &path_buf)?)
+ let do_sanity_check = import.mode != ImportMode::Location;
+ let location = location.chain(&import.location, do_sanity_check)?;
+ env.handle_import(location.clone(), |env| match import.mode {
+ ImportMode::Code => {
+ let parsed = location.fetch_dhall()?;
+ let typed = resolve_with_env(env, parsed)?.typecheck()?;
+ Ok((typed.normalize().to_hir(), typed.ty().clone()))
}
- _ => unimplemented!("{:?}", import),
- }
-}
-
-fn load_import(env: &mut ImportEnv, f: &Path) -> Result<TypedHir, Error> {
- let parsed = Parsed::parse_file(f)?;
- let typed = resolve_with_env(env, parsed)?.typecheck()?;
- Ok((typed.normalize().to_hir(), typed.ty().clone()))
+ ImportMode::RawText => {
+ let text = location.fetch_text()?;
+ let hir = Hir::new(
+ HirKind::Expr(ExprKind::TextLit(text.into())),
+ Span::Artificial,
+ );
+ Ok((hir, Type::from_builtin(Builtin::Text)))
+ }
+ ImportMode::Location => {
+ let expr = location.into_location();
+ let hir = skip_resolve(&expr)?;
+ let ty = hir.typecheck_noenv()?.ty().clone();
+ Ok((hir, ty))
+ }
+ })
}
/// Desugar the first level of the expression.
@@ -139,12 +321,10 @@ fn resolve_with_env(
env: &mut ImportEnv,
parsed: Parsed,
) -> Result<Resolved, Error> {
- let Parsed(expr, root) = parsed;
+ let Parsed(expr, location) = parsed;
let resolved =
traverse_resolve_expr(&mut NameEnv::new(), &expr, &mut |import| {
- env.handle_import(import, |env, import| {
- resolve_one_import(env, import, &root)
- })
+ resolve_one_import(env, &import, &location)
})?;
Ok(Resolved(resolved))
}
@@ -166,21 +346,15 @@ pub trait Canonicalize {
impl Canonicalize for FilePath {
fn canonicalize(&self) -> FilePath {
let mut file_path = Vec::new();
- let mut file_path_components = self.file_path.clone().into_iter();
-
- loop {
- let component = file_path_components.next();
- match component.as_ref() {
- // ───────────────────
- // canonicalize(ε) = ε
- None => break,
+ for c in &self.file_path {
+ match c.as_ref() {
// canonicalize(directory₀) = directory₁
// ───────────────────────────────────────
// canonicalize(directory₀/.) = directory₁
- Some(c) if c == "." => continue,
+ "." => continue,
- Some(c) if c == ".." => match file_path_components.next() {
+ ".." => match file_path.last() {
// canonicalize(directory₀) = ε
// ────────────────────────────
// canonicalize(directory₀/..) = /..
@@ -189,21 +363,20 @@ impl Canonicalize for FilePath {
// canonicalize(directory₀) = directory₁/..
// ──────────────────────────────────────────────
// canonicalize(directory₀/..) = directory₁/../..
- Some(ref c) if c == ".." => {
- file_path.push("..".to_string());
- file_path.push("..".to_string());
- }
+ Some(c) if c == ".." => file_path.push("..".to_string()),
// canonicalize(directory₀) = directory₁/component
// ─────────────────────────────────────────────── ; If "component" is not
// canonicalize(directory₀/..) = directory₁ ; ".."
- Some(_) => continue,
+ Some(_) => {
+ file_path.pop();
+ }
},
// canonicalize(directory₀) = directory₁
// ───────────────────────────────────────────────────────── ; If no other
// canonicalize(directory₀/component) = directory₁/component ; rule matches
- Some(c) => file_path.push(c.clone()),
+ _ => file_path.push(c.clone()),
}
}
@@ -211,21 +384,21 @@ impl Canonicalize for FilePath {
}
}
-impl<SE: Copy> Canonicalize for ImportLocation<SE> {
- fn canonicalize(&self) -> ImportLocation<SE> {
+impl<SE: Copy> Canonicalize for ImportTarget<SE> {
+ fn canonicalize(&self) -> ImportTarget<SE> {
match self {
- ImportLocation::Local(prefix, file) => {
- ImportLocation::Local(*prefix, file.canonicalize())
+ ImportTarget::Local(prefix, file) => {
+ ImportTarget::Local(*prefix, file.canonicalize())
}
- ImportLocation::Remote(url) => ImportLocation::Remote(URL {
+ ImportTarget::Remote(url) => ImportTarget::Remote(URL {
scheme: url.scheme,
authority: url.authority.clone(),
path: url.path.canonicalize(),
query: url.query.clone(),
headers: url.headers.clone(),
}),
- ImportLocation::Env(name) => ImportLocation::Env(name.to_string()),
- ImportLocation::Missing => ImportLocation::Missing,
+ ImportTarget::Env(name) => ImportTarget::Env(name.to_string()),
+ ImportTarget::Missing => ImportTarget::Missing,
}
}
}
diff --git a/dhall/src/syntax/ast/expr.rs b/dhall/src/syntax/ast/expr.rs
index bb1a5b3..ce0a3d2 100644
--- a/dhall/src/syntax/ast/expr.rs
+++ b/dhall/src/syntax/ast/expr.rs
@@ -178,7 +178,7 @@ pub enum ExprKind<SubExpr> {
Field(SubExpr, Label),
/// `e.{ x, y, z }`
Projection(SubExpr, DupTreeSet<Label>),
- /// `e.(s)`
+ /// `e.(t)`
ProjectionByExpr(SubExpr, SubExpr),
/// `x::y`
Completion(SubExpr, SubExpr),
diff --git a/dhall/src/syntax/ast/import.rs b/dhall/src/syntax/ast/import.rs
index 7bde6e0..75d7946 100644
--- a/dhall/src/syntax/ast/import.rs
+++ b/dhall/src/syntax/ast/import.rs
@@ -18,7 +18,7 @@ pub struct FilePath {
/// The location of import (i.e. local vs. remote vs. environment)
#[derive(Debug, Clone, PartialEq, Eq, Hash)]
-pub enum ImportLocation<SubExpr> {
+pub enum ImportTarget<SubExpr> {
Local(FilePrefix, FilePath),
Remote(URL<SubExpr>),
Env(String),
@@ -57,7 +57,7 @@ pub enum Hash {
#[derive(Debug, Clone, PartialEq, Eq, Hash)]
pub struct Import<SubExpr> {
pub mode: ImportMode,
- pub location: ImportLocation<SubExpr>,
+ pub location: ImportTarget<SubExpr>,
pub hash: Option<Hash>,
}
@@ -77,12 +77,12 @@ impl<SE> URL<SE> {
}
}
-impl<SE> ImportLocation<SE> {
+impl<SE> ImportTarget<SE> {
pub fn traverse_ref<'a, Err, SE2>(
&'a self,
f: impl FnOnce(&'a SE) -> Result<SE2, Err>,
- ) -> Result<ImportLocation<SE2>, Err> {
- use ImportLocation::*;
+ ) -> Result<ImportTarget<SE2>, Err> {
+ use ImportTarget::*;
Ok(match self {
Local(prefix, path) => Local(*prefix, path.clone()),
Remote(url) => Remote(url.traverse_ref(f)?),
diff --git a/dhall/src/syntax/ast/text.rs b/dhall/src/syntax/ast/text.rs
index 83aaf9a..c40f4a1 100644
--- a/dhall/src/syntax/ast/text.rs
+++ b/dhall/src/syntax/ast/text.rs
@@ -54,16 +54,6 @@ impl<SubExpr> InterpolatedTextContents<SubExpr> {
Text(s) => Text(s.clone()),
})
}
- pub fn traverse_mut<'a, E, F>(&'a mut self, mut f: F) -> Result<(), E>
- where
- F: FnMut(&'a mut SubExpr) -> Result<(), E>,
- {
- use InterpolatedTextContents::Expr;
- if let Expr(e) = self {
- f(e)?;
- }
- Ok(())
- }
pub fn map_ref<'a, SubExpr2, F>(
&'a self,
mut f: F,
@@ -77,15 +67,6 @@ impl<SubExpr> InterpolatedTextContents<SubExpr> {
Text(s) => Text(s.clone()),
}
}
- pub fn map_mut<'a, F>(&'a mut self, mut f: F)
- where
- F: FnMut(&'a mut SubExpr),
- {
- use InterpolatedTextContents::Expr;
- if let Expr(e) = self {
- f(e);
- }
- }
}
impl<SubExpr> InterpolatedText<SubExpr> {
@@ -126,16 +107,6 @@ impl<SubExpr> InterpolatedText<SubExpr> {
})
}
- pub fn traverse_mut<'a, E, F>(&'a mut self, mut f: F) -> Result<(), E>
- where
- F: FnMut(&'a mut SubExpr) -> Result<(), E>,
- {
- for (e, _) in &mut self.tail {
- f(e)?
- }
- Ok(())
- }
-
pub fn iter<'a>(
&'a self,
) -> impl Iterator<Item = InterpolatedTextContents<&'a SubExpr>> + 'a {
diff --git a/dhall/src/syntax/binary/decode.rs b/dhall/src/syntax/binary/decode.rs
index 2e50d61..bebc800 100644
--- a/dhall/src/syntax/binary/decode.rs
+++ b/dhall/src/syntax/binary/decode.rs
@@ -5,7 +5,7 @@ use std::iter::FromIterator;
use crate::error::DecodeError;
use crate::syntax;
use crate::syntax::{
- Expr, ExprKind, FilePath, FilePrefix, Hash, ImportLocation, ImportMode,
+ Expr, ExprKind, FilePath, FilePrefix, Hash, ImportMode, ImportTarget,
Integer, InterpolatedText, Label, LitKind, Natural, Scheme, Span,
UnspannedExpr, URL, V,
};
@@ -305,7 +305,7 @@ fn cbor_value_to_dhall(data: &cbor::Value) -> Result<DecodedExpr, DecodeError> {
})
.collect::<Result<_, _>>()?;
let path = FilePath { file_path };
- ImportLocation::Remote(URL {
+ ImportTarget::Remote(URL {
scheme,
authority,
path,
@@ -332,7 +332,7 @@ fn cbor_value_to_dhall(data: &cbor::Value) -> Result<DecodedExpr, DecodeError> {
})
.collect::<Result<_, _>>()?;
let path = FilePath { file_path };
- ImportLocation::Local(prefix, path)
+ ImportTarget::Local(prefix, path)
}
6 => {
let env = match rest.next() {
@@ -341,9 +341,9 @@ fn cbor_value_to_dhall(data: &cbor::Value) -> Result<DecodedExpr, DecodeError> {
"import/env".to_owned(),
))?,
};
- ImportLocation::Env(env)
+ ImportTarget::Env(env)
}
- 7 => ImportLocation::Missing,
+ 7 => ImportTarget::Missing,
_ => Err(DecodeError::WrongFormatError(
"import/type".to_owned(),
))?,
diff --git a/dhall/src/syntax/binary/encode.rs b/dhall/src/syntax/binary/encode.rs
index d2aa240..2484d8d 100644
--- a/dhall/src/syntax/binary/encode.rs
+++ b/dhall/src/syntax/binary/encode.rs
@@ -6,8 +6,8 @@ use crate::error::EncodeError;
use crate::syntax;
use crate::syntax::map::DupTreeMap;
use crate::syntax::{
- Expr, ExprKind, FilePrefix, Hash, Import, ImportLocation, ImportMode,
- Label, Scheme, V,
+ Expr, ExprKind, FilePrefix, Hash, Import, ImportMode, ImportTarget, Label,
+ Scheme, V,
};
pub(crate) fn encode(expr: &Expr) -> Result<Vec<u8>, EncodeError> {
@@ -179,10 +179,10 @@ where
use serde::ser::SerializeSeq;
let count = 4 + match &import.location {
- ImportLocation::Remote(url) => 3 + url.path.file_path.len(),
- ImportLocation::Local(_, path) => path.file_path.len(),
- ImportLocation::Env(_) => 1,
- ImportLocation::Missing => 0,
+ ImportTarget::Remote(url) => 3 + url.path.file_path.len(),
+ ImportTarget::Local(_, path) => path.file_path.len(),
+ ImportTarget::Env(_) => 1,
+ ImportTarget::Missing => 0,
};
let mut ser_seq = ser.serialize_seq(Some(count))?;
@@ -206,23 +206,23 @@ where
ser_seq.serialize_element(&U64(mode))?;
let scheme = match &import.location {
- ImportLocation::Remote(url) => match url.scheme {
+ ImportTarget::Remote(url) => match url.scheme {
Scheme::HTTP => 0,
Scheme::HTTPS => 1,
},
- ImportLocation::Local(prefix, _) => match prefix {
+ ImportTarget::Local(prefix, _) => match prefix {
FilePrefix::Absolute => 2,
FilePrefix::Here => 3,
FilePrefix::Parent => 4,
FilePrefix::Home => 5,
},
- ImportLocation::Env(_) => 6,
- ImportLocation::Missing => 7,
+ ImportTarget::Env(_) => 6,
+ ImportTarget::Missing => 7,
};
ser_seq.serialize_element(&U64(scheme))?;
match &import.location {
- ImportLocation::Remote(url) => {
+ ImportTarget::Remote(url) => {
match &url.headers {
None => ser_seq.serialize_element(&Null)?,
Some(e) => {
@@ -238,15 +238,15 @@ where
Some(x) => ser_seq.serialize_element(x)?,
};
}
- ImportLocation::Local(_, path) => {
+ ImportTarget::Local(_, path) => {
for p in path.file_path.iter() {
ser_seq.serialize_element(&p)?;
}
}
- ImportLocation::Env(env) => {
+ ImportTarget::Env(env) => {
ser_seq.serialize_element(env)?;
}
- ImportLocation::Missing => {}
+ ImportTarget::Missing => {}
}
ser_seq.end()
diff --git a/dhall/src/syntax/text/parser.rs b/dhall/src/syntax/text/parser.rs
index ba64a75..7140332 100644
--- a/dhall/src/syntax/text/parser.rs
+++ b/dhall/src/syntax/text/parser.rs
@@ -10,7 +10,7 @@ use crate::syntax::map::{DupTreeMap, DupTreeSet};
use crate::syntax::ExprKind::*;
use crate::syntax::LitKind::*;
use crate::syntax::{
- Double, Expr, FilePath, FilePrefix, Hash, ImportLocation, ImportMode,
+ Double, Expr, FilePath, FilePrefix, Hash, ImportMode, ImportTarget,
Integer, InterpolatedText, InterpolatedTextContents, Label, NaiveDouble,
Natural, Scheme, Span, UnspannedExpr, URL, V,
};
@@ -483,9 +483,9 @@ impl DhallParser {
}
#[alias(import_type)]
- fn local(input: ParseInput) -> ParseResult<ImportLocation<Expr>> {
+ fn local(input: ParseInput) -> ParseResult<ImportTarget<Expr>> {
Ok(match_nodes!(input.into_children();
- [local_path((prefix, p))] => ImportLocation::Local(prefix, p),
+ [local_path((prefix, p))] => ImportTarget::Local(prefix, p),
))
}
@@ -550,17 +550,17 @@ impl DhallParser {
}
#[alias(import_type)]
- fn http(input: ParseInput) -> ParseResult<ImportLocation<Expr>> {
- Ok(ImportLocation::Remote(match_nodes!(input.into_children();
+ fn http(input: ParseInput) -> ParseResult<ImportTarget<Expr>> {
+ Ok(ImportTarget::Remote(match_nodes!(input.into_children();
[http_raw(url)] => url,
[http_raw(url), expression(e)] => URL { headers: Some(e), ..url },
)))
}
#[alias(import_type)]
- fn env(input: ParseInput) -> ParseResult<ImportLocation<Expr>> {
+ fn env(input: ParseInput) -> ParseResult<ImportTarget<Expr>> {
Ok(match_nodes!(input.into_children();
- [environment_variable(v)] => ImportLocation::Env(v),
+ [environment_variable(v)] => ImportTarget::Env(v),
))
}
#[alias(environment_variable)]
@@ -593,8 +593,8 @@ impl DhallParser {
}
#[alias(import_type)]
- fn missing(_input: ParseInput) -> ParseResult<ImportLocation<Expr>> {
- Ok(ImportLocation::Missing)
+ fn missing(_input: ParseInput) -> ParseResult<ImportTarget<Expr>> {
+ Ok(ImportTarget::Missing)
}
fn hash(input: ParseInput) -> ParseResult<Hash> {
diff --git a/dhall/src/syntax/text/printer.rs b/dhall/src/syntax/text/printer.rs
index 8891d41..5bb987b 100644
--- a/dhall/src/syntax/text/printer.rs
+++ b/dhall/src/syntax/text/printer.rs
@@ -379,8 +379,8 @@ impl Display for Hash {
impl<SubExpr: Display> Display for Import<SubExpr> {
fn fmt(&self, f: &mut fmt::Formatter) -> Result<(), fmt::Error> {
use FilePrefix::*;
- use ImportLocation::*;
use ImportMode::*;
+ use ImportTarget::*;
let quote_if_needed = |s: &str| -> String {
if s.chars().all(|c| c.is_ascii_alphanumeric()) {
s.to_string()
@@ -406,7 +406,7 @@ impl<SubExpr: Display> Display for Import<SubExpr> {
f.write_str(&path)?;
}
Remote(url) => {
- write!(f, "{}://{}/", url.scheme, url.authority,)?;
+ write!(f, "{}://{}/", url.scheme, url.authority)?;
let path: String = url.path.file_path.iter().join("/");
f.write_str(&path)?;
if let Some(q) = &url.query {
diff --git a/dhall/src/tests.rs b/dhall/src/tests.rs
index 482f9ae..369c6cc 100644
--- a/dhall/src/tests.rs
+++ b/dhall/src/tests.rs
@@ -80,7 +80,7 @@ impl TestFile {
match self {
TestFile::Source(path)
| TestFile::Binary(path)
- | TestFile::UI(path) => PathBuf::from(path),
+ | TestFile::UI(path) => PathBuf::from("dhall").join(path),
}
}
@@ -243,6 +243,13 @@ fn run_test_stringy_error(test: Test) -> std::result::Result<(), String> {
fn run_test(test: Test) -> Result<()> {
use self::Test::*;
+ // Setup current directory to the root of the repository. Important for `as Location` tests.
+ env::set_current_dir(
+ PathBuf::from(env!("CARGO_MANIFEST_DIR")).parent().unwrap(),
+ )?;
+ // Set environment variable for import tests.
+ env::set_var("DHALL_TEST_VAR", "6 * 7");
+
match test {
ParserSuccess(expr, expected) => {
let expr = expr.parse()?;
@@ -302,6 +309,7 @@ fn run_test(test: Test) -> Result<()> {
expected.compare(expr)?;
}
}
+
Ok(())
}
diff --git a/dhall/tests/import/data/cycle.dhall b/dhall/tests/import/data/cycle.dhall
new file mode 100644
index 0000000..c370a8d
--- /dev/null
+++ b/dhall/tests/import/data/cycle.dhall
@@ -0,0 +1 @@
+../failure/cycle.dhall
diff --git a/dhall/tests/import/data/doesNotTypecheck.dhall b/dhall/tests/import/data/doesNotTypecheck.dhall
new file mode 100644
index 0000000..b748e2d
--- /dev/null
+++ b/dhall/tests/import/data/doesNotTypecheck.dhall
@@ -0,0 +1 @@
+0 0
diff --git a/dhall/tests/import/data/example.txt b/dhall/tests/import/data/example.txt
new file mode 100644
index 0000000..af5626b
--- /dev/null
+++ b/dhall/tests/import/data/example.txt
@@ -0,0 +1 @@
+Hello, world!
diff --git a/dhall/tests/import/data/fieldOrder/1.dhall b/dhall/tests/import/data/fieldOrder/1.dhall
new file mode 100644
index 0000000..797e071
--- /dev/null
+++ b/dhall/tests/import/data/fieldOrder/1.dhall
@@ -0,0 +1 @@
+{ foo = 1, bar = True }
diff --git a/dhall/tests/import/data/fieldOrder/2.dhall b/dhall/tests/import/data/fieldOrder/2.dhall
new file mode 100644
index 0000000..c16b568
--- /dev/null
+++ b/dhall/tests/import/data/fieldOrder/2.dhall
@@ -0,0 +1 @@
+{ bar = True, foo = 1 }
diff --git a/dhall/tests/import/data/importBoundary.dhall b/dhall/tests/import/data/importBoundary.dhall
new file mode 100644
index 0000000..e6f1074
--- /dev/null
+++ b/dhall/tests/import/data/importBoundary.dhall
@@ -0,0 +1,3 @@
+-- This file contains a free variable. This should be a type error, even if the variable
+-- is in scope in the importing expression
+x
diff --git a/dhall/tests/import/data/nested.dhall b/dhall/tests/import/data/nested.dhall
new file mode 100644
index 0000000..bf88f65
--- /dev/null
+++ b/dhall/tests/import/data/nested.dhall
@@ -0,0 +1 @@
+{ x = ./simple.dhall sha256:15f52ecf91c94c1baac02d5a4964b2ed8fa401641a2c8a95e8306ec7c1e3b8d2 }
diff --git a/dhall/tests/import/data/referentiallyOpaque.dhall b/dhall/tests/import/data/referentiallyOpaque.dhall
new file mode 100644
index 0000000..ff33765
--- /dev/null
+++ b/dhall/tests/import/data/referentiallyOpaque.dhall
@@ -0,0 +1,18 @@
+{- This is a "referentially opaque" import (i.e. an import that is not
+ globally addressable), which cannot be imported by a "referentially
+ transparent" import (i.e. an import that is globally addressable).
+
+ This test file is used in a failing test to verify that referentially
+ transparent imports cannot import referentially opaque imports. In the test
+ suite this file is actually imported via its GitHub URL (not its local file
+ path), so it plays the role of the referentially transparent import. Then,
+ this file attempts to import a referentially opaque import (an environment
+ variable in this case) to verify that the import fails.
+
+ For this test file we need to select a referentially opaque import that
+ would succeed if imported on its own, so that a non-compliant implementation
+ doesn't fail this test for the wrong reason (i.e. due to the import not
+ being present). We thus use the `DHALL_TEST_VAR` environment variable, that
+ is expected to be set when running import tests.
+-}
+env:DHALL_TEST_VAR as Text
diff --git a/dhall/tests/import/data/simple.dhall b/dhall/tests/import/data/simple.dhall
new file mode 100644
index 0000000..00750ed
--- /dev/null
+++ b/dhall/tests/import/data/simple.dhall
@@ -0,0 +1 @@
+3
diff --git a/dhall/tests/import/data/simpleLocation.dhall b/dhall/tests/import/data/simpleLocation.dhall
new file mode 100644
index 0000000..1d3e43b
--- /dev/null
+++ b/dhall/tests/import/data/simpleLocation.dhall
@@ -0,0 +1 @@
+./simple.dhall as Location
diff --git a/dhall/tests/import/failure/alternativeEnv.txt b/dhall/tests/import/failure/alternativeEnv.txt
new file mode 100644
index 0000000..482b68c
--- /dev/null
+++ b/dhall/tests/import/failure/alternativeEnv.txt
@@ -0,0 +1 @@
+MissingEnvVar
diff --git a/dhall/tests/import/failure/alternativeEnvMissing.txt b/dhall/tests/import/failure/alternativeEnvMissing.txt
new file mode 100644
index 0000000..4666330
--- /dev/null
+++ b/dhall/tests/import/failure/alternativeEnvMissing.txt
@@ -0,0 +1 @@
+Missing
diff --git a/dhall/tests/import/failure/cycle.txt b/dhall/tests/import/failure/cycle.txt
index 4e9488e..f5a1abf 100644
--- a/dhall/tests/import/failure/cycle.txt
+++ b/dhall/tests/import/failure/cycle.txt
@@ -1 +1 @@
-ImportCycle([Import { mode: Code, location: Local(Parent, FilePath { file_path: ["data", "cycle.dhall"] }), hash: None }, Import { mode: Code, location: Local(Parent, FilePath { file_path: ["failure", "cycle.dhall"] }), hash: None }], Import { mode: Code, location: Local(Parent, FilePath { file_path: ["data", "cycle.dhall"] }), hash: None })
+ImportCycle([Local("./dhall-lang/tests/import/data/cycle.dhall"), Local("./dhall-lang/tests/import/failure/cycle.dhall")], Local("./dhall-lang/tests/import/data/cycle.dhall"))
diff --git a/dhall/tests/import/failure/missing.txt b/dhall/tests/import/failure/missing.txt
new file mode 100644
index 0000000..4666330
--- /dev/null
+++ b/dhall/tests/import/failure/missing.txt
@@ -0,0 +1 @@
+Missing
diff --git a/dhall/tests/import/failure/referentiallyInsane.txt b/dhall/tests/import/failure/referentiallyInsane.txt
new file mode 100644
index 0000000..9b5fe91
--- /dev/null
+++ b/dhall/tests/import/failure/referentiallyInsane.txt
@@ -0,0 +1 @@
+SanityCheck
diff --git a/dhall/tests/import/failure/unit/EnvUnset.dhall b/dhall/tests/import/failure/unit/EnvUnset.dhall
new file mode 100644
index 0000000..af77cce
--- /dev/null
+++ b/dhall/tests/import/failure/unit/EnvUnset.dhall
@@ -0,0 +1 @@
+env:DHALL_TEST_UNSET
diff --git a/dhall/tests/import/failure/unit/EnvUnset.txt b/dhall/tests/import/failure/unit/EnvUnset.txt
new file mode 100644
index 0000000..482b68c
--- /dev/null
+++ b/dhall/tests/import/failure/unit/EnvUnset.txt
@@ -0,0 +1 @@
+MissingEnvVar
diff --git a/dhall/tests/import/failure/unit/EnvUnsetAsText.dhall b/dhall/tests/import/failure/unit/EnvUnsetAsText.dhall
new file mode 100644
index 0000000..9a9db6d
--- /dev/null
+++ b/dhall/tests/import/failure/unit/EnvUnsetAsText.dhall
@@ -0,0 +1 @@
+env:DHALL_TEST_UNSET as Text
diff --git a/dhall/tests/import/failure/unit/EnvUnsetAsText.txt b/dhall/tests/import/failure/unit/EnvUnsetAsText.txt
new file mode 100644
index 0000000..482b68c
--- /dev/null
+++ b/dhall/tests/import/failure/unit/EnvUnsetAsText.txt
@@ -0,0 +1 @@
+MissingEnvVar
diff --git a/dhall/tests/import/success/unit/AlternativeChain1A.dhall b/dhall/tests/import/success/unit/AlternativeChain1A.dhall
new file mode 100644
index 0000000..15fbf4b
--- /dev/null
+++ b/dhall/tests/import/success/unit/AlternativeChain1A.dhall
@@ -0,0 +1 @@
+missing ? missing ? 42
diff --git a/dhall/tests/import/success/unit/AlternativeChain1B.dhall b/dhall/tests/import/success/unit/AlternativeChain1B.dhall
new file mode 100644
index 0000000..d81cc07
--- /dev/null
+++ b/dhall/tests/import/success/unit/AlternativeChain1B.dhall
@@ -0,0 +1 @@
+42
diff --git a/dhall/tests/import/success/unit/AlternativeChain2A.dhall b/dhall/tests/import/success/unit/AlternativeChain2A.dhall
new file mode 100644
index 0000000..f3ba4b5
--- /dev/null
+++ b/dhall/tests/import/success/unit/AlternativeChain2A.dhall
@@ -0,0 +1 @@
+missing ? 42 ? 10
diff --git a/dhall/tests/import/success/unit/AlternativeChain2B.dhall b/dhall/tests/import/success/unit/AlternativeChain2B.dhall
new file mode 100644
index 0000000..d81cc07
--- /dev/null
+++ b/dhall/tests/import/success/unit/AlternativeChain2B.dhall
@@ -0,0 +1 @@
+42
diff --git a/dhall/tests/import/success/unit/AlternativeEnvA.dhall b/dhall/tests/import/success/unit/AlternativeEnvA.dhall
new file mode 100644
index 0000000..1807534
--- /dev/null
+++ b/dhall/tests/import/success/unit/AlternativeEnvA.dhall
@@ -0,0 +1 @@
+env:DHALL_TEST_UNSET ? 42
diff --git a/dhall/tests/import/success/unit/AlternativeEnvB.dhall b/dhall/tests/import/success/unit/AlternativeEnvB.dhall
new file mode 100644
index 0000000..d81cc07
--- /dev/null
+++ b/dhall/tests/import/success/unit/AlternativeEnvB.dhall
@@ -0,0 +1 @@
+42
diff --git a/dhall/tests/import/success/unit/AlternativeHashMismatchA.dhall b/dhall/tests/import/success/unit/AlternativeHashMismatchA.dhall
new file mode 100644
index 0000000..8f7fb02
--- /dev/null
+++ b/dhall/tests/import/success/unit/AlternativeHashMismatchA.dhall
@@ -0,0 +1 @@
+../../data/simple.dhall sha256:aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa ? 42
diff --git a/dhall/tests/import/success/unit/AlternativeHashMismatchB.dhall b/dhall/tests/import/success/unit/AlternativeHashMismatchB.dhall
new file mode 100644
index 0000000..d81cc07
--- /dev/null
+++ b/dhall/tests/import/success/unit/AlternativeHashMismatchB.dhall
@@ -0,0 +1 @@
+42
diff --git a/dhall/tests/import/success/unit/AlternativeImportErrorA.dhall b/dhall/tests/import/success/unit/AlternativeImportErrorA.dhall
new file mode 100644
index 0000000..9ecc640
--- /dev/null
+++ b/dhall/tests/import/success/unit/AlternativeImportErrorA.dhall
@@ -0,0 +1 @@
+missing ? 42
diff --git a/dhall/tests/import/success/unit/AlternativeImportErrorB.dhall b/dhall/tests/import/success/unit/AlternativeImportErrorB.dhall
new file mode 100644
index 0000000..d81cc07
--- /dev/null
+++ b/dhall/tests/import/success/unit/AlternativeImportErrorB.dhall
@@ -0,0 +1 @@
+42
diff --git a/dhall/tests/import/success/unit/AlternativeNestedImportErrorA.dhall b/dhall/tests/import/success/unit/AlternativeNestedImportErrorA.dhall
new file mode 100644
index 0000000..d681287
--- /dev/null
+++ b/dhall/tests/import/success/unit/AlternativeNestedImportErrorA.dhall
@@ -0,0 +1 @@
+../../failure/missing.dhall ? 42
diff --git a/dhall/tests/import/success/unit/AlternativeNestedImportErrorB.dhall b/dhall/tests/import/success/unit/AlternativeNestedImportErrorB.dhall
new file mode 100644
index 0000000..d81cc07
--- /dev/null
+++ b/dhall/tests/import/success/unit/AlternativeNestedImportErrorB.dhall
@@ -0,0 +1 @@
+42
diff --git a/dhall/tests/import/success/unit/AlternativeNoError1A.dhall b/dhall/tests/import/success/unit/AlternativeNoError1A.dhall
new file mode 100644
index 0000000..f7c9caf
--- /dev/null
+++ b/dhall/tests/import/success/unit/AlternativeNoError1A.dhall
@@ -0,0 +1 @@
+42 ? 10
diff --git a/dhall/tests/import/success/unit/AlternativeNoError1B.dhall b/dhall/tests/import/success/unit/AlternativeNoError1B.dhall
new file mode 100644
index 0000000..d81cc07
--- /dev/null
+++ b/dhall/tests/import/success/unit/AlternativeNoError1B.dhall
@@ -0,0 +1 @@
+42
diff --git a/dhall/tests/import/success/unit/AlternativeNoError2A.dhall b/dhall/tests/import/success/unit/AlternativeNoError2A.dhall
new file mode 100644
index 0000000..877afd2
--- /dev/null
+++ b/dhall/tests/import/success/unit/AlternativeNoError2A.dhall
@@ -0,0 +1 @@
+42 ? missing
diff --git a/dhall/tests/import/success/unit/AlternativeNoError2B.dhall b/dhall/tests/import/success/unit/AlternativeNoError2B.dhall
new file mode 100644
index 0000000..d81cc07
--- /dev/null
+++ b/dhall/tests/import/success/unit/AlternativeNoError2B.dhall
@@ -0,0 +1 @@
+42
diff --git a/dhall/tests/import/success/unit/AlternativeNoError3A.dhall b/dhall/tests/import/success/unit/AlternativeNoError3A.dhall
new file mode 100644
index 0000000..91bcda2
--- /dev/null
+++ b/dhall/tests/import/success/unit/AlternativeNoError3A.dhall
@@ -0,0 +1 @@
+env:DHALL_TEST_VAR ? 10
diff --git a/dhall/tests/import/success/unit/AlternativeNoError3B.dhall b/dhall/tests/import/success/unit/AlternativeNoError3B.dhall
new file mode 100644
index 0000000..d81cc07
--- /dev/null
+++ b/dhall/tests/import/success/unit/AlternativeNoError3B.dhall
@@ -0,0 +1 @@
+42
diff --git a/dhall/tests/import/success/unit/AlternativeParseErrorA.dhall b/dhall/tests/import/success/unit/AlternativeParseErrorA.dhall
new file mode 100644
index 0000000..d427c5d
--- /dev/null
+++ b/dhall/tests/import/success/unit/AlternativeParseErrorA.dhall
@@ -0,0 +1 @@
+../../data/example.txt ? 42
diff --git a/dhall/tests/import/success/unit/AlternativeParseErrorB.dhall b/dhall/tests/import/success/unit/AlternativeParseErrorB.dhall
new file mode 100644
index 0000000..d81cc07
--- /dev/null
+++ b/dhall/tests/import/success/unit/AlternativeParseErrorB.dhall
@@ -0,0 +1 @@
+42
diff --git a/dhall/tests/import/success/unit/AlternativeSubExprA.dhall b/dhall/tests/import/success/unit/AlternativeSubExprA.dhall
new file mode 100644
index 0000000..2c13f4b
--- /dev/null
+++ b/dhall/tests/import/success/unit/AlternativeSubExprA.dhall
@@ -0,0 +1 @@
+missing + 10 ? 42
diff --git a/dhall/tests/import/success/unit/AlternativeSubExprB.dhall b/dhall/tests/import/success/unit/AlternativeSubExprB.dhall
new file mode 100644
index 0000000..d81cc07
--- /dev/null
+++ b/dhall/tests/import/success/unit/AlternativeSubExprB.dhall
@@ -0,0 +1 @@
+42
diff --git a/dhall/tests/import/success/unit/AlternativeTypeErrorA.dhall b/dhall/tests/import/success/unit/AlternativeTypeErrorA.dhall
new file mode 100644
index 0000000..24ae717
--- /dev/null
+++ b/dhall/tests/import/success/unit/AlternativeTypeErrorA.dhall
@@ -0,0 +1 @@
+../../data/doesNotTypecheck.dhall ? 42
diff --git a/dhall/tests/import/success/unit/AlternativeTypeErrorB.dhall b/dhall/tests/import/success/unit/AlternativeTypeErrorB.dhall
new file mode 100644
index 0000000..d81cc07
--- /dev/null
+++ b/dhall/tests/import/success/unit/AlternativeTypeErrorB.dhall
@@ -0,0 +1 @@
+42
diff --git a/dhall/tests/import/success/unit/AsTextA.dhall b/dhall/tests/import/success/unit/AsTextA.dhall
new file mode 100644
index 0000000..9edb0ed
--- /dev/null
+++ b/dhall/tests/import/success/unit/AsTextA.dhall
@@ -0,0 +1 @@
+../../data/example.txt as Text
diff --git a/dhall/tests/import/success/unit/AsTextB.dhall b/dhall/tests/import/success/unit/AsTextB.dhall
new file mode 100644
index 0000000..1997a89
--- /dev/null
+++ b/dhall/tests/import/success/unit/AsTextB.dhall
@@ -0,0 +1,3 @@
+''
+Hello, world!
+''
diff --git a/dhall/tests/import/success/unit/EnvSetA.dhall b/dhall/tests/import/success/unit/EnvSetA.dhall
new file mode 100644
index 0000000..f851f2a
--- /dev/null
+++ b/dhall/tests/import/success/unit/EnvSetA.dhall
@@ -0,0 +1 @@
+env:DHALL_TEST_VAR
diff --git a/dhall/tests/import/success/unit/EnvSetAsTextA.dhall b/dhall/tests/import/success/unit/EnvSetAsTextA.dhall
new file mode 100644
index 0000000..139b241
--- /dev/null
+++ b/dhall/tests/import/success/unit/EnvSetAsTextA.dhall
@@ -0,0 +1 @@
+env:DHALL_TEST_VAR as Text
diff --git a/dhall/tests/import/success/unit/EnvSetAsTextB.dhall b/dhall/tests/import/success/unit/EnvSetAsTextB.dhall
new file mode 100644
index 0000000..a79bb82
--- /dev/null
+++ b/dhall/tests/import/success/unit/EnvSetAsTextB.dhall
@@ -0,0 +1 @@
+"6 * 7"
diff --git a/dhall/tests/import/success/unit/EnvSetB.dhall b/dhall/tests/import/success/unit/EnvSetB.dhall
new file mode 100644
index 0000000..d81cc07
--- /dev/null
+++ b/dhall/tests/import/success/unit/EnvSetB.dhall
@@ -0,0 +1 @@
+42
diff --git a/dhall/tests/import/success/unit/NormalizeA.dhall b/dhall/tests/import/success/unit/NormalizeA.dhall
new file mode 100644
index 0000000..2f89d08
--- /dev/null
+++ b/dhall/tests/import/success/unit/NormalizeA.dhall
@@ -0,0 +1 @@
+../../../../../dhall-lang/tests/normalization/success/unit/OperatorPlusOneAndOneA.dhall
diff --git a/dhall/tests/import/success/unit/NormalizeB.dhall b/dhall/tests/import/success/unit/NormalizeB.dhall
new file mode 100644
index 0000000..0cfbf08
--- /dev/null
+++ b/dhall/tests/import/success/unit/NormalizeB.dhall
@@ -0,0 +1 @@
+2
diff --git a/dhall/tests/import/success/unit/RemoteAsTextA.dhall b/dhall/tests/import/success/unit/RemoteAsTextA.dhall
new file mode 100644
index 0000000..472d041
--- /dev/null
+++ b/dhall/tests/import/success/unit/RemoteAsTextA.dhall
@@ -0,0 +1 @@
+https://raw.githubusercontent.com/dhall-lang/dhall-lang/0b983b92aa2222dc3e292c20550ee37dea3f41df/tests/import/data/example.txt as Text
diff --git a/dhall/tests/import/success/unit/RemoteAsTextB.dhall b/dhall/tests/import/success/unit/RemoteAsTextB.dhall
new file mode 100644
index 0000000..1997a89
--- /dev/null
+++ b/dhall/tests/import/success/unit/RemoteAsTextB.dhall
@@ -0,0 +1,3 @@
+''
+Hello, world!
+''
diff --git a/dhall/tests/import/success/unit/SimpleA.dhall b/dhall/tests/import/success/unit/SimpleA.dhall
new file mode 100644
index 0000000..035ee8b
--- /dev/null
+++ b/dhall/tests/import/success/unit/SimpleA.dhall
@@ -0,0 +1 @@
+../../data/simple.dhall
diff --git a/dhall/tests/import/success/unit/SimpleB.dhall b/dhall/tests/import/success/unit/SimpleB.dhall
new file mode 100644
index 0000000..00750ed
--- /dev/null
+++ b/dhall/tests/import/success/unit/SimpleB.dhall
@@ -0,0 +1 @@
+3
diff --git a/dhall/tests/import/success/unit/SimpleRemoteA.dhall b/dhall/tests/import/success/unit/SimpleRemoteA.dhall
new file mode 100644
index 0000000..30e0a79
--- /dev/null
+++ b/dhall/tests/import/success/unit/SimpleRemoteA.dhall
@@ -0,0 +1 @@
+https://raw.githubusercontent.com/dhall-lang/dhall-lang/0b983b92aa2222dc3e292c20550ee37dea3f41df/tests/import/data/simple.dhall
diff --git a/dhall/tests/import/success/unit/SimpleRemoteB.dhall b/dhall/tests/import/success/unit/SimpleRemoteB.dhall
new file mode 100644
index 0000000..00750ed
--- /dev/null
+++ b/dhall/tests/import/success/unit/SimpleRemoteB.dhall
@@ -0,0 +1 @@
+3
diff --git a/dhall/tests/import/success/unit/asLocation/AbsoluteA.dhall b/dhall/tests/import/success/unit/asLocation/AbsoluteA.dhall
new file mode 100644
index 0000000..dcf45d1
--- /dev/null
+++ b/dhall/tests/import/success/unit/asLocation/AbsoluteA.dhall
@@ -0,0 +1 @@
+/absolute/import as Location
diff --git a/dhall/tests/import/success/unit/asLocation/AbsoluteB.dhall b/dhall/tests/import/success/unit/asLocation/AbsoluteB.dhall
new file mode 100644
index 0000000..1c1add7
--- /dev/null
+++ b/dhall/tests/import/success/unit/asLocation/AbsoluteB.dhall
@@ -0,0 +1,2 @@
+< Environment : Text | Remote : Text | Local : Text | Missing >.Local
+ "/absolute/import"
diff --git a/dhall/tests/import/success/unit/asLocation/Canonicalize1A.dhall b/dhall/tests/import/success/unit/asLocation/Canonicalize1A.dhall
new file mode 100644
index 0000000..e636ed1
--- /dev/null
+++ b/dhall/tests/import/success/unit/asLocation/Canonicalize1A.dhall
@@ -0,0 +1 @@
+./foo/./bar/import.dhall as Location
diff --git a/dhall/tests/import/success/unit/asLocation/Canonicalize1B.dhall b/dhall/tests/import/success/unit/asLocation/Canonicalize1B.dhall
new file mode 100644
index 0000000..3a8a926
--- /dev/null
+++ b/dhall/tests/import/success/unit/asLocation/Canonicalize1B.dhall
@@ -0,0 +1,2 @@
+< Environment : Text | Remote : Text | Local : Text | Missing >.Local
+ "./dhall/tests/import/success/unit/asLocation/foo/bar/import.dhall"
diff --git a/dhall/tests/import/success/unit/asLocation/Canonicalize2A.dhall b/dhall/tests/import/success/unit/asLocation/Canonicalize2A.dhall
new file mode 100644
index 0000000..c6ef89f
--- /dev/null
+++ b/dhall/tests/import/success/unit/asLocation/Canonicalize2A.dhall
@@ -0,0 +1 @@
+./foo/baz/../bar/import.dhall as Location
diff --git a/dhall/tests/import/success/unit/asLocation/Canonicalize2B.dhall b/dhall/tests/import/success/unit/asLocation/Canonicalize2B.dhall
new file mode 100644
index 0000000..3a8a926
--- /dev/null
+++ b/dhall/tests/import/success/unit/asLocation/Canonicalize2B.dhall
@@ -0,0 +1,2 @@
+< Environment : Text | Remote : Text | Local : Text | Missing >.Local
+ "./dhall/tests/import/success/unit/asLocation/foo/bar/import.dhall"
diff --git a/dhall/tests/import/success/unit/asLocation/Canonicalize3A.dhall b/dhall/tests/import/success/unit/asLocation/Canonicalize3A.dhall
new file mode 100644
index 0000000..e6be780
--- /dev/null
+++ b/dhall/tests/import/success/unit/asLocation/Canonicalize3A.dhall
@@ -0,0 +1 @@
+./../bar/import.dhall as Location
diff --git a/dhall/tests/import/success/unit/asLocation/Canonicalize3B.dhall b/dhall/tests/import/success/unit/asLocation/Canonicalize3B.dhall
new file mode 100644
index 0000000..b223da6
--- /dev/null
+++ b/dhall/tests/import/success/unit/asLocation/Canonicalize3B.dhall
@@ -0,0 +1,2 @@
+< Environment : Text | Remote : Text | Local : Text | Missing >.Local
+ "./dhall/tests/import/success/unit/bar/import.dhall"
diff --git a/dhall/tests/import/success/unit/asLocation/Canonicalize4A.dhall b/dhall/tests/import/success/unit/asLocation/Canonicalize4A.dhall
new file mode 100644
index 0000000..ffccd47
--- /dev/null
+++ b/dhall/tests/import/success/unit/asLocation/Canonicalize4A.dhall
@@ -0,0 +1 @@
+../../bar/import.dhall as Location
diff --git a/dhall/tests/import/success/unit/asLocation/Canonicalize4B.dhall b/dhall/tests/import/success/unit/asLocation/Canonicalize4B.dhall
new file mode 100644
index 0000000..b6301f8
--- /dev/null
+++ b/dhall/tests/import/success/unit/asLocation/Canonicalize4B.dhall
@@ -0,0 +1,2 @@
+< Environment : Text | Remote : Text | Local : Text | Missing >.Local
+ "./dhall/tests/import/success/bar/import.dhall"
diff --git a/dhall/tests/import/success/unit/asLocation/Canonicalize5A.dhall b/dhall/tests/import/success/unit/asLocation/Canonicalize5A.dhall
new file mode 100644
index 0000000..7e58f0b
--- /dev/null
+++ b/dhall/tests/import/success/unit/asLocation/Canonicalize5A.dhall
@@ -0,0 +1 @@
+./foo/../../bar/import.dhall as Location
diff --git a/dhall/tests/import/success/unit/asLocation/Canonicalize5B.dhall b/dhall/tests/import/success/unit/asLocation/Canonicalize5B.dhall
new file mode 100644
index 0000000..b223da6
--- /dev/null
+++ b/dhall/tests/import/success/unit/asLocation/Canonicalize5B.dhall
@@ -0,0 +1,2 @@
+< Environment : Text | Remote : Text | Local : Text | Missing >.Local
+ "./dhall/tests/import/success/unit/bar/import.dhall"
diff --git a/dhall/tests/import/success/unit/asLocation/Chain1A.dhall b/dhall/tests/import/success/unit/asLocation/Chain1A.dhall
new file mode 100644
index 0000000..cf633fe
--- /dev/null
+++ b/dhall/tests/import/success/unit/asLocation/Chain1A.dhall
@@ -0,0 +1 @@
+./Relative1A.dhall
diff --git a/dhall/tests/import/success/unit/asLocation/Chain1B.dhall b/dhall/tests/import/success/unit/asLocation/Chain1B.dhall
new file mode 100644
index 0000000..6aee0b5
--- /dev/null
+++ b/dhall/tests/import/success/unit/asLocation/Chain1B.dhall
@@ -0,0 +1,2 @@
+< Environment : Text | Local : Text | Missing | Remote : Text >.Local
+ "./dhall/tests/import/success/unit/asLocation/some/import.dhall"
diff --git a/dhall/tests/import/success/unit/asLocation/Chain2A.dhall b/dhall/tests/import/success/unit/asLocation/Chain2A.dhall
new file mode 100644
index 0000000..cdbd10d
--- /dev/null
+++ b/dhall/tests/import/success/unit/asLocation/Chain2A.dhall
@@ -0,0 +1 @@
+./Canonicalize4A.dhall
diff --git a/dhall/tests/import/success/unit/asLocation/Chain2B.dhall b/dhall/tests/import/success/unit/asLocation/Chain2B.dhall
new file mode 100644
index 0000000..6aba54e
--- /dev/null
+++ b/dhall/tests/import/success/unit/asLocation/Chain2B.dhall
@@ -0,0 +1,2 @@
+< Environment : Text | Local : Text | Missing | Remote : Text >.Local
+ "./dhall/tests/import/success/bar/import.dhall"
diff --git a/dhall/tests/import/success/unit/asLocation/Chain3A.dhall b/dhall/tests/import/success/unit/asLocation/Chain3A.dhall
new file mode 100644
index 0000000..57751f6
--- /dev/null
+++ b/dhall/tests/import/success/unit/asLocation/Chain3A.dhall
@@ -0,0 +1 @@
+../asLocation/Canonicalize4A.dhall
diff --git a/dhall/tests/import/success/unit/asLocation/Chain3B.dhall b/dhall/tests/import/success/unit/asLocation/Chain3B.dhall
new file mode 100644
index 0000000..6aba54e
--- /dev/null
+++ b/dhall/tests/import/success/unit/asLocation/Chain3B.dhall
@@ -0,0 +1,2 @@
+< Environment : Text | Local : Text | Missing | Remote : Text >.Local
+ "./dhall/tests/import/success/bar/import.dhall"
diff --git a/dhall/tests/import/success/unit/asLocation/DontTryResolvingA.dhall b/dhall/tests/import/success/unit/asLocation/DontTryResolvingA.dhall
new file mode 100644
index 0000000..e70016c
--- /dev/null
+++ b/dhall/tests/import/success/unit/asLocation/DontTryResolvingA.dhall
@@ -0,0 +1 @@
+(missing as Location) ? 42 -- `missing` fails as an import, but definitely resolves as Location
diff --git a/dhall/tests/import/success/unit/asLocation/DontTryResolvingB.dhall b/dhall/tests/import/success/unit/asLocation/DontTryResolvingB.dhall
new file mode 100644
index 0000000..dd5e798
--- /dev/null
+++ b/dhall/tests/import/success/unit/asLocation/DontTryResolvingB.dhall
@@ -0,0 +1 @@
+< Environment : Text | Remote : Text | Local : Text | Missing >.Missing
diff --git a/dhall/tests/import/success/unit/asLocation/EnvA.dhall b/dhall/tests/import/success/unit/asLocation/EnvA.dhall
new file mode 100644
index 0000000..eb4b4a6
--- /dev/null
+++ b/dhall/tests/import/success/unit/asLocation/EnvA.dhall
@@ -0,0 +1 @@
+env:HOME as Location
diff --git a/dhall/tests/import/success/unit/asLocation/EnvB.dhall b/dhall/tests/import/success/unit/asLocation/EnvB.dhall
new file mode 100644
index 0000000..4947caa
--- /dev/null
+++ b/dhall/tests/import/success/unit/asLocation/EnvB.dhall
@@ -0,0 +1,2 @@
+< Environment : Text | Remote : Text | Local : Text | Missing >.Environment
+ "HOME"
diff --git a/dhall/tests/import/success/unit/asLocation/HashA.dhall b/dhall/tests/import/success/unit/asLocation/HashA.dhall
new file mode 100644
index 0000000..79f4fda
--- /dev/null
+++ b/dhall/tests/import/success/unit/asLocation/HashA.dhall
@@ -0,0 +1 @@
+./some/import.dhall sha256:f9340badf94a684e652e0a384f64363293d8b632d971f3453f7ee22f10ab6e75 as Location
diff --git a/dhall/tests/import/success/unit/asLocation/HashB.dhall b/dhall/tests/import/success/unit/asLocation/HashB.dhall
new file mode 100644
index 0000000..6aee0b5
--- /dev/null
+++ b/dhall/tests/import/success/unit/asLocation/HashB.dhall
@@ -0,0 +1,2 @@
+< Environment : Text | Local : Text | Missing | Remote : Text >.Local
+ "./dhall/tests/import/success/unit/asLocation/some/import.dhall"
diff --git a/dhall/tests/import/success/unit/asLocation/HomeA.dhall b/dhall/tests/import/success/unit/asLocation/HomeA.dhall
new file mode 100644
index 0000000..18cc2cd
--- /dev/null
+++ b/dhall/tests/import/success/unit/asLocation/HomeA.dhall
@@ -0,0 +1 @@
+~/some/import.dhall as Location
diff --git a/dhall/tests/import/success/unit/asLocation/HomeB.dhall b/dhall/tests/import/success/unit/asLocation/HomeB.dhall
new file mode 100644
index 0000000..8b4f0fd
--- /dev/null
+++ b/dhall/tests/import/success/unit/asLocation/HomeB.dhall
@@ -0,0 +1,2 @@
+< Environment : Text | Remote : Text | Local : Text | Missing >.Local
+ "~/some/import.dhall"
diff --git a/dhall/tests/import/success/unit/asLocation/MissingA.dhall b/dhall/tests/import/success/unit/asLocation/MissingA.dhall
new file mode 100644
index 0000000..e06a30b
--- /dev/null
+++ b/dhall/tests/import/success/unit/asLocation/MissingA.dhall
@@ -0,0 +1 @@
+missing as Location
diff --git a/dhall/tests/import/success/unit/asLocation/MissingB.dhall b/dhall/tests/import/success/unit/asLocation/MissingB.dhall
new file mode 100644
index 0000000..dd5e798
--- /dev/null
+++ b/dhall/tests/import/success/unit/asLocation/MissingB.dhall
@@ -0,0 +1 @@
+< Environment : Text | Remote : Text | Local : Text | Missing >.Missing
diff --git a/dhall/tests/import/success/unit/asLocation/Relative1A.dhall b/dhall/tests/import/success/unit/asLocation/Relative1A.dhall
new file mode 100644
index 0000000..b514f79
--- /dev/null
+++ b/dhall/tests/import/success/unit/asLocation/Relative1A.dhall
@@ -0,0 +1 @@
+./some/import.dhall as Location
diff --git a/dhall/tests/import/success/unit/asLocation/Relative1B.dhall b/dhall/tests/import/success/unit/asLocation/Relative1B.dhall
new file mode 100644
index 0000000..6aee0b5
--- /dev/null
+++ b/dhall/tests/import/success/unit/asLocation/Relative1B.dhall
@@ -0,0 +1,2 @@
+< Environment : Text | Local : Text | Missing | Remote : Text >.Local
+ "./dhall/tests/import/success/unit/asLocation/some/import.dhall"
diff --git a/dhall/tests/import/success/unit/asLocation/Relative2A.dhall b/dhall/tests/import/success/unit/asLocation/Relative2A.dhall
new file mode 100644
index 0000000..ec59586
--- /dev/null
+++ b/dhall/tests/import/success/unit/asLocation/Relative2A.dhall
@@ -0,0 +1 @@
+../some/import.dhall as Location
diff --git a/dhall/tests/import/success/unit/asLocation/Relative2B.dhall b/dhall/tests/import/success/unit/asLocation/Relative2B.dhall
new file mode 100644
index 0000000..9842f7c
--- /dev/null
+++ b/dhall/tests/import/success/unit/asLocation/Relative2B.dhall
@@ -0,0 +1,2 @@
+< Environment : Text | Local : Text | Missing | Remote : Text >.Local
+ "./dhall/tests/import/success/unit/some/import.dhall"
diff --git a/dhall/tests/import/success/unit/asLocation/RemoteA.dhall b/dhall/tests/import/success/unit/asLocation/RemoteA.dhall
new file mode 100644
index 0000000..54ea028
--- /dev/null
+++ b/dhall/tests/import/success/unit/asLocation/RemoteA.dhall
@@ -0,0 +1 @@
+https://example.com/foo/import.dhall as Location
diff --git a/dhall/tests/import/success/unit/asLocation/RemoteB.dhall b/dhall/tests/import/success/unit/asLocation/RemoteB.dhall
new file mode 100644
index 0000000..e22cfac
--- /dev/null
+++ b/dhall/tests/import/success/unit/asLocation/RemoteB.dhall
@@ -0,0 +1,2 @@
+< Environment : Text | Local : Text | Missing | Remote : Text >.Remote
+ "https://example.com/foo/import.dhall"
diff --git a/dhall/tests/import/success/unit/asLocation/RemoteCanonicalize1A.dhall b/dhall/tests/import/success/unit/asLocation/RemoteCanonicalize1A.dhall
new file mode 100644
index 0000000..3e6378e
--- /dev/null
+++ b/dhall/tests/import/success/unit/asLocation/RemoteCanonicalize1A.dhall
@@ -0,0 +1 @@
+https://example.com/foo/./bar/import.dhall as Location
diff --git a/dhall/tests/import/success/unit/asLocation/RemoteCanonicalize1B.dhall b/dhall/tests/import/success/unit/asLocation/RemoteCanonicalize1B.dhall
new file mode 100644
index 0000000..0064a13
--- /dev/null
+++ b/dhall/tests/import/success/unit/asLocation/RemoteCanonicalize1B.dhall
@@ -0,0 +1,2 @@
+< Environment : Text | Local : Text | Missing | Remote : Text >.Remote
+ "https://example.com/foo/bar/import.dhall"
diff --git a/dhall/tests/import/success/unit/asLocation/RemoteCanonicalize2A.dhall b/dhall/tests/import/success/unit/asLocation/RemoteCanonicalize2A.dhall
new file mode 100644
index 0000000..d3fd11e
--- /dev/null
+++ b/dhall/tests/import/success/unit/asLocation/RemoteCanonicalize2A.dhall
@@ -0,0 +1 @@
+https://example.com/foo/bar/../baz/import.dhall as Location
diff --git a/dhall/tests/import/success/unit/asLocation/RemoteCanonicalize2B.dhall b/dhall/tests/import/success/unit/asLocation/RemoteCanonicalize2B.dhall
new file mode 100644
index 0000000..d85236b
--- /dev/null
+++ b/dhall/tests/import/success/unit/asLocation/RemoteCanonicalize2B.dhall
@@ -0,0 +1,2 @@
+< Environment : Text | Local : Text | Missing | Remote : Text >.Remote
+ "https://example.com/foo/baz/import.dhall"
diff --git a/dhall/tests/import/success/unit/asLocation/RemoteCanonicalize3A.dhall b/dhall/tests/import/success/unit/asLocation/RemoteCanonicalize3A.dhall
new file mode 100644
index 0000000..2074fbf
--- /dev/null
+++ b/dhall/tests/import/success/unit/asLocation/RemoteCanonicalize3A.dhall
@@ -0,0 +1 @@
+https://example.com/foo/bar/../../baz/import.dhall as Location
diff --git a/dhall/tests/import/success/unit/asLocation/RemoteCanonicalize3B.dhall b/dhall/tests/import/success/unit/asLocation/RemoteCanonicalize3B.dhall
new file mode 100644
index 0000000..45a2857
--- /dev/null
+++ b/dhall/tests/import/success/unit/asLocation/RemoteCanonicalize3B.dhall
@@ -0,0 +1,2 @@
+< Environment : Text | Local : Text | Missing | Remote : Text >.Remote
+ "https://example.com/baz/import.dhall"
diff --git a/dhall/tests/import/success/unit/asLocation/RemoteCanonicalize4A.dhall b/dhall/tests/import/success/unit/asLocation/RemoteCanonicalize4A.dhall
new file mode 100644
index 0000000..9358f44
--- /dev/null
+++ b/dhall/tests/import/success/unit/asLocation/RemoteCanonicalize4A.dhall
@@ -0,0 +1 @@
+https://example.com/../bar/import.dhall as Location
diff --git a/dhall/tests/import/success/unit/asLocation/RemoteCanonicalize4B.dhall b/dhall/tests/import/success/unit/asLocation/RemoteCanonicalize4B.dhall
new file mode 100644
index 0000000..b5ccbcd
--- /dev/null
+++ b/dhall/tests/import/success/unit/asLocation/RemoteCanonicalize4B.dhall
@@ -0,0 +1,2 @@
+< Environment : Text | Local : Text | Missing | Remote : Text >.Remote
+ "https://example.com/../bar/import.dhall"
diff --git a/dhall/tests/import/success/unit/asLocation/RemoteChain1A.dhall b/dhall/tests/import/success/unit/asLocation/RemoteChain1A.dhall
new file mode 100644
index 0000000..7d081ab
--- /dev/null
+++ b/dhall/tests/import/success/unit/asLocation/RemoteChain1A.dhall
@@ -0,0 +1 @@
+https://raw.githubusercontent.com/dhall-lang/dhall-lang/0b983b92aa2222dc3e292c20550ee37dea3f41df/tests/import/data/simpleLocation.dhall
diff --git a/dhall/tests/import/success/unit/asLocation/RemoteChain1B.dhall b/dhall/tests/import/success/unit/asLocation/RemoteChain1B.dhall
new file mode 100644
index 0000000..8ac2c6b
--- /dev/null
+++ b/dhall/tests/import/success/unit/asLocation/RemoteChain1B.dhall
@@ -0,0 +1,2 @@
+< Environment : Text | Local : Text | Missing | Remote : Text >.Remote
+ "https://raw.githubusercontent.com/dhall-lang/dhall-lang/0b983b92aa2222dc3e292c20550ee37dea3f41df/tests/import/data/simple.dhall"
diff --git a/dhall/tests/import/success/unit/asLocation/RemoteChain2A.dhall b/dhall/tests/import/success/unit/asLocation/RemoteChain2A.dhall
new file mode 100644
index 0000000..9929517
--- /dev/null
+++ b/dhall/tests/import/success/unit/asLocation/RemoteChain2A.dhall
@@ -0,0 +1 @@
+https://raw.githubusercontent.com/Nadrieril/dhall-rust/f7d8c64a9799f139ad65427c2518376adb9e2e2f/dhall/tests/import/success/unit/asLocation/Canonicalize3A.dhall
diff --git a/dhall/tests/import/success/unit/asLocation/RemoteChain2B.dhall b/dhall/tests/import/success/unit/asLocation/RemoteChain2B.dhall
new file mode 100644
index 0000000..685dc04
--- /dev/null
+++ b/dhall/tests/import/success/unit/asLocation/RemoteChain2B.dhall
@@ -0,0 +1,2 @@
+< Environment : Text | Local : Text | Missing | Remote : Text >.Remote
+ "https://raw.githubusercontent.com/Nadrieril/dhall-rust/f7d8c64a9799f139ad65427c2518376adb9e2e2f/dhall/tests/import/success/unit/bar/import.dhall"
diff --git a/dhall/tests/import/success/unit/asLocation/RemoteChain3A.dhall b/dhall/tests/import/success/unit/asLocation/RemoteChain3A.dhall
new file mode 100644
index 0000000..851108c
--- /dev/null
+++ b/dhall/tests/import/success/unit/asLocation/RemoteChain3A.dhall
@@ -0,0 +1 @@
+https://raw.githubusercontent.com/Nadrieril/dhall-rust/f7d8c64a9799f139ad65427c2518376adb9e2e2f/dhall/tests/import/success/unit/asLocation/Canonicalize5A.dhall
diff --git a/dhall/tests/import/success/unit/asLocation/RemoteChain3B.dhall b/dhall/tests/import/success/unit/asLocation/RemoteChain3B.dhall
new file mode 100644
index 0000000..685dc04
--- /dev/null
+++ b/dhall/tests/import/success/unit/asLocation/RemoteChain3B.dhall
@@ -0,0 +1,2 @@
+< Environment : Text | Local : Text | Missing | Remote : Text >.Remote
+ "https://raw.githubusercontent.com/Nadrieril/dhall-rust/f7d8c64a9799f139ad65427c2518376adb9e2e2f/dhall/tests/import/success/unit/bar/import.dhall"
diff --git a/dhall/tests/normalization/success/regression/NaturalFoldExtraArgA.dhall b/dhall/tests/normalization/success/regression/NaturalFoldExtraArgA.dhall
new file mode 100644
index 0000000..3a69d1e
--- /dev/null
+++ b/dhall/tests/normalization/success/regression/NaturalFoldExtraArgA.dhall
@@ -0,0 +1 @@
+Natural/fold 0 (Bool -> Bool) (λ(_ : (Bool -> Bool)) → λ(_ : Bool) → True) (λ(_ : Bool) → False) True
diff --git a/dhall/tests/normalization/success/regression/NaturalFoldExtraArgB.dhall b/dhall/tests/normalization/success/regression/NaturalFoldExtraArgB.dhall
new file mode 100644
index 0000000..bc59c12
--- /dev/null
+++ b/dhall/tests/normalization/success/regression/NaturalFoldExtraArgB.dhall
@@ -0,0 +1 @@
+False
diff --git a/dhall/tests/normalization/success/regression/TrickyBinderIdentityA.dhall b/dhall/tests/normalization/success/regression/TrickyBinderIdentityA.dhall
new file mode 100644
index 0000000..5d72bbe
--- /dev/null
+++ b/dhall/tests/normalization/success/regression/TrickyBinderIdentityA.dhall
@@ -0,0 +1 @@
+let T = Natural let ap = λ(f : T → List T) -> λ(x : T) -> f x in ap (λ(x : T) -> ap (λ(y : T) -> [x, y]) 1) 0
diff --git a/dhall/tests/normalization/success/regression/TrickyBinderIdentityB.dhall b/dhall/tests/normalization/success/regression/TrickyBinderIdentityB.dhall
new file mode 100644
index 0000000..28233fb
--- /dev/null
+++ b/dhall/tests/normalization/success/regression/TrickyBinderIdentityB.dhall
@@ -0,0 +1 @@
+[ 0, 1 ]
diff --git a/dhall/tests/normalization/success/unit/TextLitNested1A.dhall b/dhall/tests/normalization/success/unit/TextLitNested1A.dhall
new file mode 100644
index 0000000..104dc41
--- /dev/null
+++ b/dhall/tests/normalization/success/unit/TextLitNested1A.dhall
@@ -0,0 +1 @@
+λ(x: Text) → "${""}${x}"
diff --git a/dhall/tests/normalization/success/unit/TextLitNested1B.dhall b/dhall/tests/normalization/success/unit/TextLitNested1B.dhall
new file mode 100644
index 0000000..631a6cf
--- /dev/null
+++ b/dhall/tests/normalization/success/unit/TextLitNested1B.dhall
@@ -0,0 +1 @@
+λ(x : Text) → x
diff --git a/dhall/tests/normalization/success/unit/TextLitNested2A.dhall b/dhall/tests/normalization/success/unit/TextLitNested2A.dhall
new file mode 100644
index 0000000..5b4ae6e
--- /dev/null
+++ b/dhall/tests/normalization/success/unit/TextLitNested2A.dhall
@@ -0,0 +1 @@
+λ(x: Text) → "${"${x}"}"
diff --git a/dhall/tests/normalization/success/unit/TextLitNested2B.dhall b/dhall/tests/normalization/success/unit/TextLitNested2B.dhall
new file mode 100644
index 0000000..631a6cf
--- /dev/null
+++ b/dhall/tests/normalization/success/unit/TextLitNested2B.dhall
@@ -0,0 +1 @@
+λ(x : Text) → x
diff --git a/dhall/tests/normalization/success/unit/TextLitNested3A.dhall b/dhall/tests/normalization/success/unit/TextLitNested3A.dhall
new file mode 100644
index 0000000..d57ac64
--- /dev/null
+++ b/dhall/tests/normalization/success/unit/TextLitNested3A.dhall
@@ -0,0 +1 @@
+λ(x: Text) → "${"${""}"}${x}"
diff --git a/dhall/tests/normalization/success/unit/TextLitNested3B.dhall b/dhall/tests/normalization/success/unit/TextLitNested3B.dhall
new file mode 100644
index 0000000..631a6cf
--- /dev/null
+++ b/dhall/tests/normalization/success/unit/TextLitNested3B.dhall
@@ -0,0 +1 @@
+λ(x : Text) → x
diff --git a/dhall/tests/normalization/success/unit/TextShowEmptyA.dhall b/dhall/tests/normalization/success/unit/TextShowEmptyA.dhall
new file mode 100644
index 0000000..589f65d
--- /dev/null
+++ b/dhall/tests/normalization/success/unit/TextShowEmptyA.dhall
@@ -0,0 +1 @@
+Text/show ""
diff --git a/dhall/tests/normalization/success/unit/TextShowEmptyB.dhall b/dhall/tests/normalization/success/unit/TextShowEmptyB.dhall
new file mode 100644
index 0000000..8fbbe76
--- /dev/null
+++ b/dhall/tests/normalization/success/unit/TextShowEmptyB.dhall
@@ -0,0 +1 @@
+"\"\""
diff --git a/dhall/tests/parser/failure/assertBinding.txt b/dhall/tests/parser/failure/assertBinding.txt
new file mode 100644
index 0000000..4253a31
--- /dev/null
+++ b/dhall/tests/parser/failure/assertBinding.txt
@@ -0,0 +1,6 @@
+ --> 1:5
+ |
+1 | let assert = 2 in 1␍␊
+ | ^---
+ |
+ = expected simple_label
diff --git a/dhall/tests/parser/failure/spacing/AssertNoSpace.txt b/dhall/tests/parser/failure/spacing/AssertNoSpace.txt
index 0e83988..a98c16a 100644
--- a/dhall/tests/parser/failure/spacing/AssertNoSpace.txt
+++ b/dhall/tests/parser/failure/spacing/AssertNoSpace.txt
@@ -1,6 +1,6 @@
- --> 1:8
+ --> 1:1
|
1 | assert :T␊
- | ^---
+ | ^---
|
- = expected EOI, import_alt, bool_or, natural_plus, text_append, list_append, bool_and, natural_times, bool_eq, bool_ne, combine, combine_types, equivalent, prefer, arrow, import_hashed, or primitive_expression
+ = expected expression
diff --git a/dhall/tests/parser/failure/unit/AssertNoAnnotation.dhall b/dhall/tests/parser/failure/unit/AssertNoAnnotation.dhall
new file mode 100644
index 0000000..6019020
--- /dev/null
+++ b/dhall/tests/parser/failure/unit/AssertNoAnnotation.dhall
@@ -0,0 +1 @@
+assert
diff --git a/dhall/tests/parser/failure/unit/AssertNoAnnotation.txt b/dhall/tests/parser/failure/unit/AssertNoAnnotation.txt
new file mode 100644
index 0000000..435e325
--- /dev/null
+++ b/dhall/tests/parser/failure/unit/AssertNoAnnotation.txt
@@ -0,0 +1,6 @@
+ --> 1:1
+ |
+1 | assert␊
+ | ^---
+ |
+ = expected expression
diff --git a/dhall/tests/parser/success/unit/EmptyRecordLiteralA.dhall b/dhall/tests/parser/success/unit/EmptyRecordLiteralA.dhall
new file mode 100644
index 0000000..339130f
--- /dev/null
+++ b/dhall/tests/parser/success/unit/EmptyRecordLiteralA.dhall
@@ -0,0 +1 @@
+{=}
diff --git a/dhall/tests/parser/success/unit/EmptyRecordLiteralB.dhallb b/dhall/tests/parser/success/unit/EmptyRecordLiteralB.dhallb
new file mode 100644
index 0000000..58e2e39
--- /dev/null
+++ b/dhall/tests/parser/success/unit/EmptyRecordLiteralB.dhallb
@@ -0,0 +1 @@
+ \ No newline at end of file
diff --git a/dhall/tests/parser/success/unit/EmptyRecordLiteralB.diag b/dhall/tests/parser/success/unit/EmptyRecordLiteralB.diag
new file mode 100644
index 0000000..8ead206
--- /dev/null
+++ b/dhall/tests/parser/success/unit/EmptyRecordLiteralB.diag
@@ -0,0 +1 @@
+[8, {}]
diff --git a/dhall/tests/parser/success/unit/LetAnnotA.dhall b/dhall/tests/parser/success/unit/LetAnnotA.dhall
new file mode 100644
index 0000000..c7d29f8
--- /dev/null
+++ b/dhall/tests/parser/success/unit/LetAnnotA.dhall
@@ -0,0 +1 @@
+let x: T = y in e
diff --git a/dhall/tests/parser/success/unit/LetAnnotB.dhallb b/dhall/tests/parser/success/unit/LetAnnotB.dhallb
new file mode 100644
index 0000000..4e3a7e4
--- /dev/null
+++ b/dhall/tests/parser/success/unit/LetAnnotB.dhallb
Binary files differ
diff --git a/dhall/tests/parser/success/unit/LetAnnotB.diag b/dhall/tests/parser/success/unit/LetAnnotB.diag
new file mode 100644
index 0000000..36791e0
--- /dev/null
+++ b/dhall/tests/parser/success/unit/LetAnnotB.diag
@@ -0,0 +1 @@
+[25, "x", ["T", 0], ["y", 0], ["e", 0]]
diff --git a/dhall/tests/parser/success/unit/LetNoAnnotA.dhall b/dhall/tests/parser/success/unit/LetNoAnnotA.dhall
new file mode 100644
index 0000000..64d30e6
--- /dev/null
+++ b/dhall/tests/parser/success/unit/LetNoAnnotA.dhall
@@ -0,0 +1 @@
+let x = y in e
diff --git a/dhall/tests/parser/success/unit/LetNoAnnotB.dhallb b/dhall/tests/parser/success/unit/LetNoAnnotB.dhallb
new file mode 100644
index 0000000..79a2384
--- /dev/null
+++ b/dhall/tests/parser/success/unit/LetNoAnnotB.dhallb
Binary files differ
diff --git a/dhall/tests/parser/success/unit/LetNoAnnotB.diag b/dhall/tests/parser/success/unit/LetNoAnnotB.diag
new file mode 100644
index 0000000..a23f605
--- /dev/null
+++ b/dhall/tests/parser/success/unit/LetNoAnnotB.diag
@@ -0,0 +1 @@
+[25, "x", null, ["y", 0], ["e", 0]]
diff --git a/dhall/tests/parser/success/unit/ToMapA.dhall b/dhall/tests/parser/success/unit/ToMapA.dhall
new file mode 100644
index 0000000..ea04391
--- /dev/null
+++ b/dhall/tests/parser/success/unit/ToMapA.dhall
@@ -0,0 +1 @@
+toMap x
diff --git a/dhall/tests/parser/success/unit/ToMapAnnotA.dhall b/dhall/tests/parser/success/unit/ToMapAnnotA.dhall
new file mode 100644
index 0000000..ad65b07
--- /dev/null
+++ b/dhall/tests/parser/success/unit/ToMapAnnotA.dhall
@@ -0,0 +1 @@
+toMap x : T
diff --git a/dhall/tests/parser/success/unit/ToMapAnnotB.dhallb b/dhall/tests/parser/success/unit/ToMapAnnotB.dhallb
new file mode 100644
index 0000000..4b53587
--- /dev/null
+++ b/dhall/tests/parser/success/unit/ToMapAnnotB.dhallb
Binary files differ
diff --git a/dhall/tests/parser/success/unit/ToMapAnnotB.diag b/dhall/tests/parser/success/unit/ToMapAnnotB.diag
new file mode 100644
index 0000000..8e511fb
--- /dev/null
+++ b/dhall/tests/parser/success/unit/ToMapAnnotB.diag
@@ -0,0 +1 @@
+[27, ["x", 0], ["T", 0]]
diff --git a/dhall/tests/parser/success/unit/ToMapB.dhallb b/dhall/tests/parser/success/unit/ToMapB.dhallb
new file mode 100644
index 0000000..25ecd95
--- /dev/null
+++ b/dhall/tests/parser/success/unit/ToMapB.dhallb
Binary files differ
diff --git a/dhall/tests/parser/success/unit/ToMapB.diag b/dhall/tests/parser/success/unit/ToMapB.diag
new file mode 100644
index 0000000..5d25b39
--- /dev/null
+++ b/dhall/tests/parser/success/unit/ToMapB.diag
@@ -0,0 +1 @@
+[27, ["x", 0]]
diff --git a/dhall/tests/parser/success/unit/VariableQuotedWithSpaceA.dhall b/dhall/tests/parser/success/unit/VariableQuotedWithSpaceA.dhall
new file mode 100644
index 0000000..a1f4d02
--- /dev/null
+++ b/dhall/tests/parser/success/unit/VariableQuotedWithSpaceA.dhall
@@ -0,0 +1 @@
+` x `
diff --git a/dhall/tests/parser/success/unit/VariableQuotedWithSpaceB.dhallb b/dhall/tests/parser/success/unit/VariableQuotedWithSpaceB.dhallb
new file mode 100644
index 0000000..56d9cd9
--- /dev/null
+++ b/dhall/tests/parser/success/unit/VariableQuotedWithSpaceB.dhallb
Binary files differ
diff --git a/dhall/tests/parser/success/unit/VariableQuotedWithSpaceB.diag b/dhall/tests/parser/success/unit/VariableQuotedWithSpaceB.diag
new file mode 100644
index 0000000..035d650
--- /dev/null
+++ b/dhall/tests/parser/success/unit/VariableQuotedWithSpaceB.diag
@@ -0,0 +1 @@
+[" x ", 0]
diff --git a/dhall/tests/type-inference/failure/unit/FunctionTypeOutputTypeNotAType.dhall b/dhall/tests/type-inference/failure/unit/FunctionTypeOutputTypeNotAType.dhall
new file mode 100644
index 0000000..94b32f9
--- /dev/null
+++ b/dhall/tests/type-inference/failure/unit/FunctionTypeOutputTypeNotAType.dhall
@@ -0,0 +1 @@
+Bool -> 1
diff --git a/dhall/tests/type-inference/failure/unit/FunctionTypeOutputTypeNotAType.txt b/dhall/tests/type-inference/failure/unit/FunctionTypeOutputTypeNotAType.txt
new file mode 100644
index 0000000..bcc44a5
--- /dev/null
+++ b/dhall/tests/type-inference/failure/unit/FunctionTypeOutputTypeNotAType.txt
@@ -0,0 +1,7 @@
+Type error: error: Expected a type, found: `1`
+ --> <current file>:1:8
+ |
+1 | Bool -> 1
+ | ^ this has type: `Natural`
+ |
+ = help: An expression in type position must have type `Type`, `Kind` or `Sort`
diff --git a/dhall/tests/type-inference/failure/unit/LetInSort.dhall b/dhall/tests/type-inference/failure/unit/LetInSort.dhall
new file mode 100644
index 0000000..125ab28
--- /dev/null
+++ b/dhall/tests/type-inference/failure/unit/LetInSort.dhall
@@ -0,0 +1 @@
+\(x: let x = 0 in Sort) -> 1
diff --git a/dhall/tests/type-inference/failure/unit/LetInSort.txt b/dhall/tests/type-inference/failure/unit/LetInSort.txt
new file mode 100644
index 0000000..07be298
--- /dev/null
+++ b/dhall/tests/type-inference/failure/unit/LetInSort.txt
@@ -0,0 +1,6 @@
+Type error: error: Sort does not have a type
+ --> <current file>:1:18
+ |
+1 | \(x: let x = 0 in Sort) -> 1
+ | ^^^^ Sort does not have a type
+ |
diff --git a/dhall/tests/type-inference/failure/unit/MergeBool.dhall b/dhall/tests/type-inference/failure/unit/MergeBool.dhall
new file mode 100644
index 0000000..01e7e3f
--- /dev/null
+++ b/dhall/tests/type-inference/failure/unit/MergeBool.dhall
@@ -0,0 +1 @@
+\(x: { True: Natural, False: Natural }) -> merge x True
diff --git a/dhall/tests/type-inference/failure/unit/MergeBool.txt b/dhall/tests/type-inference/failure/unit/MergeBool.txt
new file mode 100644
index 0000000..209def1
--- /dev/null
+++ b/dhall/tests/type-inference/failure/unit/MergeBool.txt
@@ -0,0 +1,6 @@
+Type error: error: Merge2ArgMustBeUnionOrOptional
+ --> <current file>:1:43
+ |
+1 | \(x: { True: Natural, False: Natural }) -> merge x True
+ | ^^^^^^^^^^^^ Merge2ArgMustBeUnionOrOptional
+ |
diff --git a/dhall/tests/type-inference/failure/unit/NestedAnnotInnerWrong.dhall b/dhall/tests/type-inference/failure/unit/NestedAnnotInnerWrong.dhall
new file mode 100644
index 0000000..7e5c8ec
--- /dev/null
+++ b/dhall/tests/type-inference/failure/unit/NestedAnnotInnerWrong.dhall
@@ -0,0 +1 @@
+(0 : Bool) : Natural
diff --git a/dhall/tests/type-inference/failure/unit/NestedAnnotInnerWrong.txt b/dhall/tests/type-inference/failure/unit/NestedAnnotInnerWrong.txt
new file mode 100644
index 0000000..b56db54
--- /dev/null
+++ b/dhall/tests/type-inference/failure/unit/NestedAnnotInnerWrong.txt
@@ -0,0 +1,6 @@
+Type error: error: annot mismatch: Natural != Bool
+ --> <current file>:1:1
+ |
+1 | (0 : Bool) : Natural
+ | ^ annot mismatch: Natural != Bool
+ |
diff --git a/dhall/tests/type-inference/failure/unit/NestedAnnotOuterWrong.dhall b/dhall/tests/type-inference/failure/unit/NestedAnnotOuterWrong.dhall
new file mode 100644
index 0000000..67a1526
--- /dev/null
+++ b/dhall/tests/type-inference/failure/unit/NestedAnnotOuterWrong.dhall
@@ -0,0 +1 @@
+(0 : Natural) : Bool
diff --git a/dhall/tests/type-inference/failure/unit/NestedAnnotOuterWrong.txt b/dhall/tests/type-inference/failure/unit/NestedAnnotOuterWrong.txt
new file mode 100644
index 0000000..2f07b8d
--- /dev/null
+++ b/dhall/tests/type-inference/failure/unit/NestedAnnotOuterWrong.txt
@@ -0,0 +1,6 @@
+Type error: error: annot mismatch: Natural != Bool
+ --> <current file>:1:1
+ |
+1 | (0 : Natural) : Bool
+ | ^^^^^^^^^^^ annot mismatch: Natural != Bool
+ |
diff --git a/dhall/tests/type-inference/success/CacheImportsA.dhall b/dhall/tests/type-inference/success/CacheImportsA.dhall
new file mode 100644
index 0000000..7180b19
--- /dev/null
+++ b/dhall/tests/type-inference/success/CacheImportsA.dhall
@@ -0,0 +1,6 @@
+{-
+ This URL returns (probably) a different result for each request. This test
+ ensures that import results for a given URL are correctly cached within an
+ execution of dhall.
+-}
+let _ = assert : https://csrng.net/csrng/csrng.php?min=0&max=1000 as Text === https://csrng.net/csrng/csrng.php?min=0&max=1000 as Text in 0
diff --git a/dhall/tests/type-inference/success/CacheImportsB.dhall b/dhall/tests/type-inference/success/CacheImportsB.dhall
new file mode 100644
index 0000000..2f184a4
--- /dev/null
+++ b/dhall/tests/type-inference/success/CacheImportsB.dhall
@@ -0,0 +1 @@
+Natural
diff --git a/dhall/tests/type-inference/success/CacheImportsCanonicalizeA.dhall b/dhall/tests/type-inference/success/CacheImportsCanonicalizeA.dhall
new file mode 100644
index 0000000..e7f4dcd
--- /dev/null
+++ b/dhall/tests/type-inference/success/CacheImportsCanonicalizeA.dhall
@@ -0,0 +1,5 @@
+{-
+ This URL returns (probably) a different result for each request. This test
+ ensures that import locations are canonicalized before being cached.
+-}
+let _ = assert : https://csrng.net/csrng/csrng.php?min=0&max=1000 as Text === https://csrng.net/csrng/../csrng/csrng.php?min=0&max=1000 as Text in 0
diff --git a/dhall/tests/type-inference/success/CacheImportsCanonicalizeB.dhall b/dhall/tests/type-inference/success/CacheImportsCanonicalizeB.dhall
new file mode 100644
index 0000000..2f184a4
--- /dev/null
+++ b/dhall/tests/type-inference/success/CacheImportsCanonicalizeB.dhall
@@ -0,0 +1 @@
+Natural
diff --git a/dhall/tests/type-inference/success/regression/LambdaInLetScoping1A.dhall b/dhall/tests/type-inference/success/regression/LambdaInLetScoping1A.dhall
new file mode 100644
index 0000000..72f866f
--- /dev/null
+++ b/dhall/tests/type-inference/success/regression/LambdaInLetScoping1A.dhall
@@ -0,0 +1 @@
+let T = 0 in λ(T : Type) → λ(x : T) → 1
diff --git a/dhall/tests/type-inference/success/regression/LambdaInLetScoping1B.dhall b/dhall/tests/type-inference/success/regression/LambdaInLetScoping1B.dhall
new file mode 100644
index 0000000..42bfeec
--- /dev/null
+++ b/dhall/tests/type-inference/success/regression/LambdaInLetScoping1B.dhall
@@ -0,0 +1 @@
+∀(T : Type) → ∀(x : T) → Natural
diff --git a/dhall/tests/type-inference/success/regression/LambdaInLetScoping2A.dhall b/dhall/tests/type-inference/success/regression/LambdaInLetScoping2A.dhall
new file mode 100644
index 0000000..30fd03c
--- /dev/null
+++ b/dhall/tests/type-inference/success/regression/LambdaInLetScoping2A.dhall
@@ -0,0 +1 @@
+(λ(T : Type) → let x = 0 in λ(x : T) → x) : ∀(T : Type) → ∀(x : T) → T
diff --git a/dhall/tests/type-inference/success/regression/LambdaInLetScoping2B.dhall b/dhall/tests/type-inference/success/regression/LambdaInLetScoping2B.dhall
new file mode 100644
index 0000000..20aa0d3
--- /dev/null
+++ b/dhall/tests/type-inference/success/regression/LambdaInLetScoping2B.dhall
@@ -0,0 +1 @@
+∀(T : Type) → ∀(x : T) → T
diff --git a/dhall/tests/type-inference/success/regression/RecursiveRecordTypeMergeTripleCollisionA.dhall b/dhall/tests/type-inference/success/regression/RecursiveRecordTypeMergeTripleCollisionA.dhall
new file mode 100644
index 0000000..c7b7fb4
--- /dev/null
+++ b/dhall/tests/type-inference/success/regression/RecursiveRecordTypeMergeTripleCollisionA.dhall
@@ -0,0 +1 @@
+{ x : { a : Bool } } ⩓ { x : { b : Bool } } ⩓ { x : { c : Bool } }
diff --git a/dhall/tests/type-inference/success/regression/RecursiveRecordTypeMergeTripleCollisionB.dhall b/dhall/tests/type-inference/success/regression/RecursiveRecordTypeMergeTripleCollisionB.dhall
new file mode 100644
index 0000000..245bc9d
--- /dev/null
+++ b/dhall/tests/type-inference/success/regression/RecursiveRecordTypeMergeTripleCollisionB.dhall
@@ -0,0 +1 @@
+Type
diff --git a/dhall/tests/type-inference/success/regression/TodoA.dhall b/dhall/tests/type-inference/success/regression/TodoA.dhall
new file mode 100644
index 0000000..9d5ef34
--- /dev/null
+++ b/dhall/tests/type-inference/success/regression/TodoA.dhall
@@ -0,0 +1 @@
+λ(todo : ∀(a : Type) → a) → todo
diff --git a/dhall/tests/type-inference/success/regression/TodoB.dhall b/dhall/tests/type-inference/success/regression/TodoB.dhall
new file mode 100644
index 0000000..e0091f2
--- /dev/null
+++ b/dhall/tests/type-inference/success/regression/TodoB.dhall
@@ -0,0 +1 @@
+∀(todo : ∀(a : Type) → a) → ∀(a : Type) → a