Skip to content

Conversation

vdukhovni
Copy link
Contributor

thLiteral    :: Quote m => String -> Code m ByteString
thHexLiteral :: Quote m => String -> Code m ByteString

The former rejects inputs with non-octet code points above 0xFF. The latter rejects odd-length inputs or inputs with characters other than non-hexadecimal digits.

@vdukhovni vdukhovni force-pushed the th-splices branch 2 times, most recently from 70f1a6a to b53c921 Compare August 16, 2025 08:26
@vdukhovni
Copy link
Contributor Author

@Bodigrim I don't understand what's going on with CI. Any help appreciated.

@Bodigrim
Copy link
Contributor

@vdukhovni no idea tbh. Maybe something changed under the hood, either in runner images or in the haskell action.

@vdukhovni
Copy link
Contributor Author

I have very little experience tuning GitHub CI. Any chance someone can help?

@Bodigrim
Copy link
Contributor

It seems it was an intermittent failure with https://github.com/haskell-actions/setup. I don't think you need to touch CI setup in this PR.

@vdukhovni
Copy link
Contributor Author

Thanks, indeed most of the problems appear to have been transient. I reverted the CI changes, and the only failure so far is with OpenBSD, which reports:
⚠️ Not enough compute credits to prioritize tasks!

Otherwise, no issues. So I think I'm done, unless you'd prefer to name the two functions differently. The names thLiteral and thHexLiteral were a best effort choice at the time, but one can probably make a case for other choices if these don't appeal.

@vdukhovni
Copy link
Contributor Author

Review request: @hsyl20 @Bodigrim @clyring

Copy link
Contributor

@hsyl20 hsyl20 left a comment

Choose a reason for hiding this comment

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

LGTM

I would prefer more explicit names: something like literalFromAscii (or literalFromChar8) and literalFromHex

@vdukhovni
Copy link
Contributor Author

LGTM

I would prefer more explicit names: something like literalFromAscii (or literalFromChar8) and literalFromHex

Many thanks for the prompt review! I'm about to push a fixup for all the nits, and what remains then is to reach consensus on the splice names. Of the above I prefer literalFromChar8 over literalFromAscii and have no objections to literalFromHex. I take it you don't see any benefit from including a th prefix to make it clear these are splices rather than directly usable functions?

@hsyl20
Copy link
Contributor

hsyl20 commented Aug 21, 2025

I take it you don't see any benefit from including a th prefix to make it clear these are splices rather than directly usable functions?

Yes the type and literal already convey that imo.

@vdukhovni vdukhovni force-pushed the th-splices branch 2 times, most recently from c5906d9 to 28a0cb6 Compare August 21, 2025 14:09
@vdukhovni vdukhovni force-pushed the th-splices branch 2 times, most recently from 83cf073 to 2f5671a Compare August 23, 2025 03:11
@Bodigrim Bodigrim requested a review from clyring August 24, 2025 10:28
@vdukhovni
Copy link
Contributor Author

@hsyl20, @Bodigrim Many thanks for the reviews, much appreciated. If at some point you find some more review cycles, I've revived, rebased and improved #569, so reviews there would also be great.

@vdukhovni
Copy link
Contributor Author

@hsyl20 @clyring @Bodigrim I believe this is done. Please let me know if anything is missing.

import Data.Bits ((.&.))
import Data.Bits ((.|.), (.&.), complement, shiftL)
import Data.Char (ord)
import Data.Foldable (foldr')
Copy link
Member

Choose a reason for hiding this comment

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

The unqualified foldr' briefly confused me. (Actually, why are these quote-generators defined in D.B.Internal.Type instead of the exposed Data.ByteString?)

literalFromChar8 "" = [||empty||]
literalFromChar8 s = case foldr' op (Octets 0 []) s of
Octets n ws -> liftTyped (unsafePackLenBytes n ws)
Hichar i w -> liftCode $ fail $ "non-octet character '\\" ++
Copy link
Member

Choose a reason for hiding this comment

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

@TeofilC Would this liftCode $ fail $ ... stuff require any adjustments to your template-haskell-lift plans?

Copy link

Choose a reason for hiding this comment

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

Thanks for the headsup. This should be fine.

@vdukhovni vdukhovni force-pushed the th-splices branch 2 times, most recently from 8b3189d to d8c2d02 Compare September 14, 2025 10:53
@vdukhovni
Copy link
Contributor Author

Anything still to do on my end?

Copy link
Member

@clyring clyring left a comment

Choose a reason for hiding this comment

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

LGTM, but:

  • I would want to pluralize the name literalFromChar8 (which looks singular). Perhaps just literalFromChar8s or literalFromString8. But there probably isn't much room for confusion anyway.
  • I suspect you will want to make a clean commit message.

@vdukhovni
Copy link
Contributor Author

LGTM, but:

  • I would want to pluralize the name literalFromChar8 (which looks singular). Perhaps just literalFromChar8s or literalFromString8. But there probably isn't much room for confusion anyway.

I ultimately don't have strong views about the naming, so willing to make changes, but my intuition is that Char8 suffix is fairly natural, given the existing Data.ByteString.Char8. Do others also prefer avoiding Char8 here?
If change is needed, I'd propose literalFromOctetString.

  • I suspect you will want to make a clean commit message.

Sure, I'll squash and update the commit message.

@clyring
Copy link
Member

clyring commented Oct 16, 2025

I ultimately don't have strong views about the naming, so willing to make changes, but my intuition is that Char8 suffix is fairly natural, given the existing Data.ByteString.Char8. Do others also prefer avoiding Char8 here?
If change is needed, I'd propose literalFromOctetString.

The Char8 aspect is indeed very natural. My concern is just that literalFromChar8 reads a bit like a function that takes only one Char8. literalFromOctetString sounds good.

    literalFromOctetString :: Quote m => String -> Code m ByteString
    literalFromHex         :: Quote m => String -> Code m ByteString

The former rejects inputs with non-octet code points above 0xFF.
The latter rejects odd-length inputs or inputs with characters
other than non-hexadecimal digits.
@vdukhovni
Copy link
Contributor Author

Sadly, not enough info about why the OpenBSD CI run failed, looks unrelated to this PR, as various other *BSD jobs have been failing in other PRs recently.

,,,
[16 of 16] Linking dist-newstyle/build/x86_64-openbsd/ghc-9.8.3/bytestring-0.13.0.0/t/bytestring-tests/build/bytestring-tests/bytestring-tests
ld.lld: warning: OSThreads.c(OSThreads.thr_o:(createAttachedOSThread) in archive /usr/local/lib/ghc-9.8.3/lib/../lib/x86_64-openbsd-ghc-9.8.3/rts-1.0.2/libHSrts-1.0.2_thr.a): warning: strcpy() is almost always misused, please use strlcpy()
ld.lld: warning: EventLogWriter.c(EventLogWriter.thr_o:(initEventLogFileWriter) in archive /usr/local/lib/ghc-9.8.3/lib/../lib/x86_64-openbsd-ghc-9.8.3/rts-1.0.2/libHSrts-1.0.2_thr.a): warning: sprintf() is often misused, please use snprintf()
Running 1 test suites...
Test suite bytestring-tests: RUNNING...
Test suite bytestring-tests: FAIL
Test suite logged to:
/tmp/cirrus-ci-build/./dist-newstyle/build/x86_64-openbsd/ghc-9.8.3/bytestring-0.13.0.0/t/bytestring-tests/test/bytestring-0.13.0.0-bytestring-tests.log
0 of 1 test suites (0 of 1 test cases) passed.
Error: [Cabal-7125]
Tests failed for test:bytestring-tests from bytestring-0.13.0.0.

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.

6 participants