Skip to content

Inspection tests fail if -O0 is forced #634

Open

Description

@Bodigrim

Hackage builder for some reason enforces -O0, which causes inspection tests to fail:

$ cabal run test:tests --ghc-options='-O0' -- --hide-successes
All
  Properties
    folds-unfolds
      folds
        _S_foldl'_from_foldlM' ==~ _S_foldl':                              FAIL
          LHS:
              _S_foldl'_from_foldlM'
                = ... \ (f :: a -> Char -> a) (x :: a) ->
                        . runIdentity
                          (foldlM'
                             $fMonadIdentity
                             ((\ (i :: a) (c :: Char) -> f i c) `cast` <Co:9> :: ...)
                             x)
          RHS: _S_foldl' = ... inline foldl'
          Use -p '/_S_foldl'\''_from_foldlM'\'' ==~ _S_foldl'\''/' to rerun this test only.
    lowlevel
      misc
        t_literal_foo
          mentions none of Char, List:                                     FAIL
            t_literal_foo :: Text
            t_literal_foo = pack lvl_sNbt

            lvl_sNbs :: Addr#
            lvl_sNbs = "foo"#

            lvl_sNbt :: [Char]
            lvl_sNbt = unpackCString# lvl_sNbs

            Use -p '/mentions none of Char, List/' to rerun this test only.
          uses none of pack, unstream, map, safe, streamList:              FAIL
            t_literal_foo :: Text
            t_literal_foo = pack lvl_sNbt

            lvl_sNbs :: Addr#
            lvl_sNbs = "foo"#

            lvl_sNbt :: [Char]
            lvl_sNbt = unpackCString# lvl_sNbs

            Use -p '/uses none of pack, unstream, map, safe, streamList/' to rerun this test only.
          uses none of unpackCString#, unpackCStringUtf8#:                 FAIL
            t_literal_foo :: Text
            t_literal_foo = pack lvl_sNbt

            lvl_sNbs :: Addr#
            lvl_sNbs = "foo"#

            lvl_sNbt :: [Char]
            lvl_sNbt = unpackCString# lvl_sNbs

            Use -p '/uses none of unpackCString#, unpackCStringUtf8#/' to rerun this test only.

...which is kinda expected, but annoying.

In the wild: https://hackage.haskell.org/package/text-2.1.2/reports/2

Activity

  1. Lysxia commented on May 15, 2025

    @Lysxia
    Contributor

    Is there a way to detect that -O0 was used and disable the tests if so?

  2. Bodigrim commented on May 15, 2025

    @Bodigrim
    ContributorAuthor

    The test itself forces -O1:

    #ifdef MIN_VERSION_tasty_inspection_testing
    {-# LANGUAGE TemplateHaskell #-}
    {-# OPTIONS_GHC -O -dsuppress-all -dno-suppress-type-signatures -fplugin=Test.Tasty.Inspection.Plugin #-}
    #endif

    The problem is that the library was built with -O0, so whatever optimizations are enabled in tests they do not have access to optimized implementations of required functions.

    There are probably a few ways to solve this (such as force -O1 in required library modules, or set -fexpose-all-unfoldings), although neither solution feels robust enough. After all, maybe having a "failed tests" on Hackage is not that big deal. Also I don't know why Hackage wants to run tests with -O0.

  3. Lysxia commented on May 15, 2025

    @Lysxia
    Contributor

    One idea is to create a cabal flag specifically for enabling inspection tests and setting -O in the library.

  4. Bodigrim commented on Oct 29, 2025

    @Bodigrim
    ContributorAuthor

    One way would be to put the following definition into, say, Data.Text.Internal.Private:

    isLibraryBuiltWithOptimizationsEnabled = False 
    {-# RULE "are optimizations on?" isLibraryBuiltWithOptimizationsEnabled = True #-}
    

    and then check the value of isLibraryBuiltWithOptimizationsEnabled in the test suite. Dunno, is it too evil?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions