Skip to content

Use Base.o_* instead of raw {#const O_*} - #339

Merged
hasufell merged 3 commits into
haskell:masterfrom
GulinSS:wip/T24603
Apr 30, 2025
Merged

Use Base.o_* instead of raw {#const O_*}#339
hasufell merged 3 commits into
haskell:masterfrom
GulinSS:wip/T24603

Conversation

@GulinSS

@GulinSS GulinSS commented Apr 25, 2025

Copy link
Copy Markdown
Contributor

stage1 cross compilers can use different values instead of system-defined. GHC JS Backend overrides these constants to be compatible with Node.js environment.

Details of investigation.

Interface stability tests have the following overridden constants:

  o_APPEND :: GHC.Internal.Foreign.C.Types.CInt
  o_BINARY :: GHC.Internal.Foreign.C.Types.CInt
  o_CREAT :: GHC.Internal.Foreign.C.Types.CInt
  o_EXCL :: GHC.Internal.Foreign.C.Types.CInt
  o_NOCTTY :: GHC.Internal.Foreign.C.Types.CInt
  o_NONBLOCK :: GHC.Internal.Foreign.C.Types.CInt
  o_RDONLY :: GHC.Internal.Foreign.C.Types.CInt
  o_RDWR :: GHC.Internal.Foreign.C.Types.CInt
  o_TRUNC :: GHC.Internal.Foreign.C.Types.CInt
  o_WRONLY :: GHC.Internal.Foreign.C.Types.CInt

Blocks: https://gitlab.haskell.org/ghc/ghc/-/merge_requests/13856

@GulinSS
GulinSS marked this pull request as draft April 25, 2025 16:38
@GulinSS

GulinSS commented Apr 25, 2025

Copy link
Copy Markdown
Contributor Author

Set to draft while https://gitlab.haskell.org/ghc/ghc/-/merge_requests/13856 is in progress

`stage1` cross compilers could use different values instead of
system-defined. GHC JS Backend change these constants to be compatible
with Node.js environment.
@GulinSS

GulinSS commented Apr 25, 2025

Copy link
Copy Markdown
Contributor Author

It became actual after

https://gitlab.haskell.org/ghc/ghc/-/issues/25190
https://gitlab.haskell.org/ghc/ghc/-/issues/23697

Which were raised after

haskell/cabal#10366

These changes are for restoring consistency across cross compile targets with packages which have custom Setup.hs build rules.

@GulinSS

GulinSS commented Apr 27, 2025

Copy link
Copy Markdown
Contributor Author

@GulinSS
GulinSS marked this pull request as ready for review April 27, 2025 05:09
@hasufell
hasufell requested a review from Bodigrim April 28, 2025 13:22
-- them overridden.
-- For example GHC JS Backend provides its own constants
-- which should be used at the target of cross compilation
-- into Node.JS environment.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Could you reference a GHC source file which contain overriding logic for JS backend? It would help future readers.

@GulinSS GulinSS Apr 29, 2025

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Yes, we have a test which can be referenced for such overridings:

grep -rn testsuite -e 'o_CREAT'

testsuite/tests/interface-stability/base-exports.stdout-javascript-unknown-ghcjs:13590:  o_CREAT :: GHC.Internal.Foreign.C.Types.CInt
testsuite/tests/interface-stability/base-exports.stdout:10544:  o_CREAT :: GHC.Internal.Foreign.C.Types.CInt
testsuite/tests/interface-stability/base-exports.stdout-mingw32:10812:  o_CREAT :: GHC.Internal.Foreign.C.Types.CInt
testsuite/tests/interface-stability/base-exports.stdout-ws-32:10544:  o_CREAT :: GHC.Internal.Foreign.C.Types.CInt

So, files testsuite/tests/interface-stability/base-exports.stdout* can be useful to determine which targets have foreigns (exports? 🤔 ).

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Actual overrides are collected at ./libraries/ghc-internal/src/GHC/Internal/System/Posix/Internals.hs. For example o_CREAT:

JS Backend

foreign import javascript unsafe "(() => { return h$base_o_creat; })"    o_CREAT    :: CInt

Other

foreign import ccall unsafe "HsBase.h __hscore_o_creat"  o_CREAT  :: CInt

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Probably need create a [Note] there at sources?

fdOption2Int NonBlockingRead = (#const O_NONBLOCK)
fdOption2Int AppendOnWrite = (Base.o_APPEND)
fdOption2Int NonBlockingRead = (Base.o_NONBLOCK)
fdOption2Int SynchronousWrites = (#const O_SYNC)

@Bodigrim Bodigrim Apr 28, 2025

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Is there a reason for the inconsistency, beyond GHC exporting incomplete set? Could you please raise an issue on GHC side to provide a complete set in future? (We can leave unix source code inconsistent for the time being, but I'd like this to be rectified in future)

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

@Bodigrim Bodigrim left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

I'm fine with accepting a tactical fix, but it raises questions about viability of hsc2hs for cross-compilation. What's the plan? CC @bgamari @mpickering

@GulinSS

GulinSS commented Apr 29, 2025

Copy link
Copy Markdown
Contributor Author

I'm fine with accepting a tactical fix, but it raises questions about viability of hsc2hs for cross-compilation. What's the plan? CC @bgamari @mpickering

@bgamari sent a response here. If I understand it correctly, tactical fix is OK but for further changes we need to do something with base if CLC OK. The main point is to prevent having a dependency on ghc-internal from unix and use base instead.

@Bodigrim Bodigrim left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

LGTM, but we really need someone to resurrect CI before merging. I won't have time for this until next week unfortunately.

@GulinSS

GulinSS commented Apr 30, 2025

Copy link
Copy Markdown
Contributor Author

resurrect CI before merging

I did obvious fixes for the CI, but need some clues about NetBSD / OpenBSD.

@hasufell

hasufell commented Apr 30, 2025

Copy link
Copy Markdown
Member

NetBSD and OpenBSD are constantly broken. I don't mind if we ignore them.

@GulinSS

GulinSS commented Apr 30, 2025

Copy link
Copy Markdown
Contributor Author

NetBSD is surprisingly fine. But OpenBSD is failed because 7.6 is a minimal version. We use image of 7.5 which was not updated by its author. Cirrus itself does not support OpenBSD OOTB.

I have no rights to merge, so, I am needed to wait.

@hasufell
hasufell merged commit 47d5fc4 into haskell:master Apr 30, 2025
@GulinSS
GulinSS deleted the wip/T24603 branch April 30, 2025 07:09
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.

3 participants