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

Make Span::initial() a const fn #143

Merged
merged 1 commit into from
Jan 5, 2020
Merged

Make Span::initial() a const fn #143

merged 1 commit into from
Jan 5, 2020

Conversation

etaoins
Copy link
Contributor

@etaoins etaoins commented Jan 4, 2020

In Arret nearly every intermediate data structure contains a Span so our generated code can be mapped back to source location. However, they're rarely used until we need to report a diagnostic or generate debugging information.

This led to a common pattern in unit tests where we use a dummy span to test intermediate transformations where we aren't starting from actual Arret source. This used to be a const called EMPTY_SPAN which can be used to build other const data structures used for testing.

In etaoins/arret#160 we needed to switch to an empty_span() function because there is no longer a const constructor for Span.

We can't make Span::new const yet because const functions are not powerful enough. However, Span::initial is perfect for this use case.

In Arret nearly every intermediate data structure contains a `Span` so
our generated code can be mapped back to source location. However,
they're rarely used until we need to report a diagnostic or generate
debugging information.

This led to a common pattern in unit tests where we use a dummy span to
test intermediate transformations where we aren't starting from actual
Arret source. This used to be a `const` called `EMPTY_SPAN` which can be
used to build other `const` data structures used for testing.

In etaoins/arret#160 we needed to switch to an `empty_span()` function
because there is no longer a `const` constructor for `Span`.

We can't make `Span::new` `const` yet because const functions are not
powerful enough. However, `Span::initial` is perfect for this use case.
@brendanzab
Copy link
Owner

Thanks!

etaoins added a commit to etaoins/arret that referenced this pull request Jan 5, 2020
This is enabled by brendanzab/codespan#143 which requires us to take a
Git dependency until `codespan` 0.7 is released.
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.

2 participants