Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
THIS IS A BREAKING CHANGE
When porting Arret from
codespan
0.3 (see etaoins/arret#160) one of the missing features was being able use non-String
types for storing source.Arret has two potential uses for this:
When loading native libraries exposing Arret functions (known as RFI libraries) their Arret type is specified as a per-function
&'static str
. An example can be seen here:https://github.com/etaoins/arret/blob/dfc41bed1c992cc57023359743f68c639d667f25/stdlib/rust/list.rs#L8
With
codespan
0.3 we usedCow<'static str>
to avoid allocating a newString
for every RFI function by pointing directly inside the loaded library's binary.Arret is multithreaded but needs to maintain a global
Files
instance to allocateFileId
s. It uses a read-write lock for thread safety and is sensitive to contention on that lock in some circumstances.Because we need a
FileId
in our AST we can't parse the source to AST until we've added it toFiles
. However, becauseFiles
takes ownership of the source we need to hold a read lock onFiles
to usefiles.source()
. The effectively serialises loading source files across all threads.Previously we used
Arc<FileMap>
to drop the lock onCodeMap
and then parse theFileMap
locklessly. The API doesn't allow this anymore but we could useSource = Arc<str>
to similar effect.Unfortunately the above two uses are mutually exclusive using standard library types. However, either one is an improvement over
String
and a crate type likesupercow
could potentially satisfy both uses.This is a breaking change due to adding a new generic parameter to
Files
. I initially attempted to use a default ofString
but this doesn't work forFiles::new
due to rust-lang/rust#27336. See rust-lang/wg-allocators#1 for an analogous case to this.