Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Introduce Canonicalize #99

Merged
merged 12 commits into from Oct 12, 2019
Merged

Conversation

FintanH
Copy link
Collaborator

@FintanH FintanH commented Aug 12, 2019

Fixes #76

Refactor of File to be the combination of Directory and the file name,where Directory is the Vector of component paths.

The refactor meant changing some sections of the code where we were
parsing and manipulating Files/Directories.

This also includes a new trait Canonicalization which is needed for
import logic.

This is just the introduction of the trait, but calling it needs to be added as well. From what I could see that's involved with import chaining, is that right? Do we have that yet?

where Directory is the Vector of component paths.

The refactor meant changing some sections of the code where we were
parsing and manipulating Files/Directories.

This also includes a new trait Canonicalization which is needed for
import logic.
Copy link
Owner

@Nadrieril Nadrieril left a comment

Choose a reason for hiding this comment

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

Overall looks good !
I do have one big question : why is the file/directory distinction useful ? Since empty paths are allowed, we may have paths without a file, so what's the benefit of keeping the last component separatedly ?

dhall/src/phase/binary.rs Outdated Show resolved Hide resolved
dhall_syntax/src/parser.rs Outdated Show resolved Hide resolved
dhall_syntax/src/core/import.rs Outdated Show resolved Hide resolved
dhall_syntax/src/core/import.rs Outdated Show resolved Hide resolved
dhall_syntax/src/core/import.rs Outdated Show resolved Hide resolved
authority: url.authority.clone(),
path: url.path.canonicalize(),
query: url.query.clone(),
headers: url.headers.clone().map(|boxed_hash| Box::new(boxed_hash.canonicalize())),
Copy link
Owner

Choose a reason for hiding this comment

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

I believe you could use as_ref instead of clone here, since canonicalize only needs a reference.

dhall_syntax/src/parser.rs Outdated Show resolved Hide resolved
_ => unimplemented!("{:?}", import),
};
Ok(load_import(&path, import_cache, import_stack).map_err(|e| {
Ok(load_import(&path_buf, import_cache, import_stack).map_err(|e| {
ImportError::Recursive(import.clone(), Box::new(e))
})?)
}
Copy link
Owner

Choose a reason for hiding this comment

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

Since this feature isn't tested by the tests from dhall-lang, could you add some tests here ? You don't need to test every case, but a few basic ones would ensure it works and we don't accidentally break it in the future.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

I think I just need to add the tests, and we're good to go here.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Just to check I'm on the right page. I have a skeleton test where ? is place holder for values:

    #[test]
    test_resolve_import_local() {
        let import = Import {
            mode: RawText,
            location: Local(?FilePrefix, FilePath { file_path: ?file_path }),
            hash: None,
        };
        let root = LocalDir(?cwd);
        let import_cache = HashMap::new();
        let import_stack = vec![];
        let import_result = resolve_import(import, root, import_cache, import_stack);
        assert_eq!(import_result, Ok(?some_result));
    }

Copy link
Owner

Choose a reason for hiding this comment

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

Oh I'm so sorry I missed this comment >< I was thinking more simply to just test canonicalize. For example

#[test]
test_canonicalize_whatever() {
    let filepath = FilePath {filepath = vec!["foo", "..", "bar"]};
    let expected = FilePath {filepath = vec!["bar"]};
    assert_eq!(filepath.canonicalize(), expected);
}

Copy link
Owner

Choose a reason for hiding this comment

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

Yeah sorry, that really wasn't clear from the diff this comment is pointing to

@Nadrieril
Copy link
Owner

@FintanH Need a hand with the code or with reading the semantics ?

@FintanH
Copy link
Collaborator Author

FintanH commented Sep 2, 2019

@Nadrieril: thanks for checking in ❤️ Sorry I've left this so long, got snapped up with switching jobs and what not. I have some time off now and fully on the Rust train 🚂 I'll look at this during the week and possibly a bit at MuniHac 😁

@Nadrieril
Copy link
Owner

@FintanH Since the parser changed completely in #110, I took the liberty of merging the latest master into your PR so that you don't need do to it yourself

@FintanH
Copy link
Collaborator Author

FintanH commented Sep 3, 2019

@Nadrieril I have a weird one:

error[E0308]: mismatched types
   --> dhall_generated_parser/build.rs:100:39
    |
100 |         pest_generator::derive_parser(pest, false)
    |                                       ^^^^ expected struct `proc_macro2::TokenStream`, found a different struct `proc_macro2::TokenStream`
    |
    = note: expected type `proc_macro2::TokenStream` (struct `proc_macro2::TokenStream`)
               found type `proc_macro2::TokenStream` (struct `proc_macro2::TokenStream`)
note: Perhaps two different versions of crate `proc_macro2` are being used?
   --> dhall_generated_parser/build.rs:100:39
    |
100 |         pest_generator::derive_parser(pest, false)
    |                                       ^^^^

error: aborting due to previous error

I did a cargo clean, cargo update, and cargo build is throwing that error 🤔

@Nadrieril
Copy link
Owner

Ah yeah it seems there was a conflict between the version of proc_macro2 used by pest and the one used by quote. This should be fixed on master now

@Nadrieril
Copy link
Owner

Actually we may be able to test canonicalization with normal tests using as Location.
Anyways this PR is fine and tests are not that important for now, so I'll just merge it.
Thanks a lot, and sorry for the wait !

@Nadrieril Nadrieril merged commit 8a8eeea into Nadrieril:master Oct 12, 2019
@FintanH
Copy link
Collaborator Author

FintanH commented Oct 12, 2019

Thanks! Sorry for my lack of work on it towards the end 😅 been very busy!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Canonicalization of imports
2 participants