Skip to content

chore: Include C headers explicitly in stubs - #277

Open
Kara-Zor-El wants to merge 1 commit into
grain-lang:mainfrom
Kara-Zor-El:Kara-Zor-El/implicit-includes
Open

chore: Include C headers explicitly in stubs#277
Kara-Zor-El wants to merge 1 commit into
grain-lang:mainfrom
Kara-Zor-El:Kara-Zor-El/implicit-includes

Conversation

@Kara-Zor-El

Copy link
Copy Markdown

I was looking at the Grain issues and noticed this one: grain-lang/grain#2315. I wanted to confirm if it was solved or not and decided to run a quick check of include-what-you-use (a neat tool that checks that you actually include dependencies).

Certain compilers (and specific versions of the same compiler) have implicit includes but they are not guaranteed to work elsewhere.

Lmk if any questions

# note: sysroot is only needed on macos
for f in src/*.c src/*.h; do
  include-what-you-use \
  -isysroot "$(xcrun --show-sdk-path)" \
  -I "$(ocamlc -where)" \
  -I "$HOME/.opam/default/lib/libbinaryen/c" \
  -I src \
  -Xiwyu --no_fwd_decls \
  "$f"
done
Results:

(_string.h ones can be ignored)

src/array_type.c should add these lines:
#include "caml/misc.h"      // for CAMLprim

src/array_type.c should remove these lines:
- #include <caml/fail.h>  // lines 3-3

The full include-list for src/array_type.c:
#include <caml/memory.h>    // for caml__roots_block, CAMLparam1, CAMLreturn
#include <caml/mlvalues.h>  // for value, Val_bool, Val_int
#include "binaryen-c.h"     // for BinaryenHeapType, BinaryenArrayTypeGetEle...
#include "caml/misc.h"      // for CAMLprim
#include "ocaml_helpers.h"  // for BinaryenHeapType_val, alloc_BinaryenType
---

src/export.c should add these lines:
#include "caml/misc.h"      // for CAMLprim

src/export.c should remove these lines:
- #include <caml/fail.h>  // lines 3-3

The full include-list for src/export.c:
#include <caml/alloc.h>     // for caml_copy_string
#include <caml/memory.h>    // for caml__roots_block, CAMLreturn, CAMLparam1
#include <caml/mlvalues.h>  // for value, Val_int, Int_val, Val_unit
#include "binaryen-c.h"     // for BinaryenExportRef, BinaryenModuleRef, Bin...
#include "caml/misc.h"      // for CAMLprim
#include "ocaml_helpers.h"  // for Safe_String_val, BinaryenModuleRef_val
---

src/expression.c should add these lines:
#include <stdbool.h>        // for bool
#include <stddef.h>         // for NULL
#include <stdint.h>         // for int8_t
#include "caml/misc.h"      // for CAMLprim

src/expression.c should remove these lines:
- #include <caml/fail.h>  // lines 3-3

The full include-list for src/expression.c:
#include <caml/alloc.h>     // for caml_copy_string, caml_alloc_some
#include <caml/memory.h>    // for caml__roots_block, CAMLreturn, CAMLparam1
#include <caml/mlvalues.h>  // for value, Val_int, Val_unit, Int_val, Field
#include <stdbool.h>        // for bool
#include <stddef.h>         // for NULL
#include <stdint.h>         // for int8_t
#include "binaryen-c.h"     // for BinaryenExpressionRef, BinaryenModuleRef
#include "caml/misc.h"      // for CAMLprim
#include "ocaml_helpers.h"  // for BinaryenExpressionRef_val, alloc_Binaryen...
---

src/function.c should add these lines:
#include "caml/misc.h"      // for CAMLprim

src/function.c should remove these lines:
- #include <caml/fail.h>  // lines 3-3

The full include-list for src/function.c:
#include <caml/alloc.h>     // for caml_copy_string
#include <caml/memory.h>    // for caml__roots_block, CAMLreturn, CAMLparam1
#include <caml/mlvalues.h>  // for value, Int_val, Val_unit, Val_int, Field
#include "binaryen-c.h"     // for BinaryenFunctionRef, BinaryenModuleRef
#include "caml/misc.h"      // for CAMLprim
#include "ocaml_helpers.h"  // for BinaryenFunctionRef_val, BinaryenModuleRe...
---

src/global.c should add these lines:
#include <stdint.h>         // for int8_t
#include "caml/misc.h"      // for CAMLprim

src/global.c should remove these lines:
- #include <caml/fail.h>  // lines 3-3

The full include-list for src/global.c:
#include <caml/alloc.h>     // for caml_copy_string
#include <caml/memory.h>    // for caml__roots_block, CAMLreturn, CAMLparam1
#include <caml/mlvalues.h>  // for value, Bool_val, Int_val, Val_bool, Val_int
#include <stdint.h>         // for int8_t
#include "binaryen-c.h"     // for BinaryenGlobalRef, BinaryenModuleRef, Bin...
#include "caml/misc.h"      // for CAMLprim
#include "ocaml_helpers.h"  // for BinaryenModuleRef_val, BinaryenGlobalRef_val
---

src/heap_type.c should add these lines:
#include <stdbool.h>        // for bool
#include "caml/misc.h"      // for CAMLprim

src/heap_type.c should remove these lines:
- #include <caml/fail.h>  // lines 3-3

The full include-list for src/heap_type.c:
#include <caml/memory.h>    // for caml__roots_block, CAMLreturn, CAMLparam1
#include <caml/mlvalues.h>  // for value, Val_bool
#include <stdbool.h>        // for bool
#include "binaryen-c.h"     // for BinaryenHeapType, BinaryenHeapTypeAny
#include "caml/misc.h"      // for CAMLprim
#include "ocaml_helpers.h"  // for alloc_BinaryenHeapType, BinaryenHeapType_val
---

src/import.c should add these lines:
#include <stdint.h>         // for uint8_t
#include "caml/misc.h"      // for CAMLprim

src/import.c should remove these lines:
- #include <caml/fail.h>  // lines 3-3

The full include-list for src/import.c:
#include <caml/alloc.h>     // for caml_copy_string
#include <caml/memory.h>    // for caml__roots_block, CAMLreturn, CAMLparam1
#include <caml/mlvalues.h>  // for value, Val_unit, Bool_val
#include <stdint.h>         // for uint8_t
#include "binaryen-c.h"     // for BinaryenModuleRef, BinaryenType, Binaryen...
#include "caml/misc.h"      // for CAMLprim
#include "ocaml_helpers.h"  // for Safe_String_val, BinaryenModuleRef_val
---

src/literal.c should add these lines:
#include <stdint.h>         // for int32_t, int64_t
#include "caml/misc.h"      // for CAMLprim

src/literal.c should remove these lines:
- #include <caml/fail.h>  // lines 3-3

The full include-list for src/literal.c:
#include <caml/memory.h>    // for caml__roots_block, CAMLparam1, CAMLreturn
#include <caml/mlvalues.h>  // for value, Int32_val, Int64_val, Double_val
#include <stdint.h>         // for int32_t, int64_t
#include "binaryen-c.h"     // for BinaryenLiteral, BinaryenLiteralFloat32Bits
#include "caml/misc.h"      // for CAMLprim
#include "ocaml_helpers.h"  // for alloc_BinaryenLiteral
---

src/memory.c should add these lines:
#include <stdbool.h>        // for bool
#include <stddef.h>         // for size_t
#include "caml/alloc.h"     // for caml_alloc_some, caml_alloc_string
#include "caml/misc.h"      // for CAMLprim

src/memory.c should remove these lines:
- #include <caml/fail.h>  // lines 3-3

The full include-list for src/memory.c:
#include <caml/memory.h>    // for caml__roots_block, CAMLreturn, CAMLparam2
#include <caml/mlvalues.h>  // for value, Field, Val_bool, Val_int, Bool_val
#include <stdbool.h>        // for bool
#include <stddef.h>         // for size_t
#include "binaryen-c.h"     // for BinaryenModuleRef, BinaryenIndex, Binarye...
#include "caml/alloc.h"     // for caml_alloc_some, caml_alloc_string
#include "caml/misc.h"      // for CAMLprim
#include "ocaml_helpers.h"  // for Safe_String_val, BinaryenModuleRef_val
---

src/module_feature.c should add these lines:
#include <stdint.h>         // for uint32_t
#include "caml/misc.h"      // for CAMLprim

src/module_feature.c should remove these lines:
- #include <caml/fail.h>  // lines 3-3

The full include-list for src/module_feature.c:
#include <caml/memory.h>    // for caml__roots_block, CAMLreturn, CAMLparam1
#include <caml/mlvalues.h>  // for value, Val_int, Int_val, Val_unit
#include <stdint.h>         // for uint32_t
#include "binaryen-c.h"     // for BinaryenModuleRef, BinaryenFeatureAll
#include "caml/misc.h"      // for CAMLprim
#include "ocaml_helpers.h"  // for BinaryenModuleRef_val
---

src/module.c should add these lines:
#include <stdlib.h>         // for free, NULL
#include "caml/misc.h"      // for CAMLprim

src/module.c should remove these lines:
- #include <caml/fail.h>  // lines 4-4

The full include-list for src/module.c:
#include <caml/alloc.h>     // for caml_copy_string, caml_alloc_initialized_...
#include <caml/memory.h>    // for caml__roots_block, CAMLreturn, CAMLparam1
#include <caml/mlvalues.h>  // for value, Val_unit, Field, Val_int, caml_str...
#include <stdlib.h>         // for free, NULL
#include "binaryen-c.h"     // for BinaryenModuleRef, BinaryenAddCustomSection
#include "caml/misc.h"      // for CAMLprim
#include "ocaml_helpers.h"  // for BinaryenModuleRef_val, Safe_String_val
---

src/ocaml_helpers.h should add these lines:
#include <_string.h>        // for memcpy
#include "caml/misc.h"      // for CAMLprim

src/ocaml_helpers.h should remove these lines:
- #include <caml/alloc.h>  // lines 6-6
- #include <caml/callback.h>  // lines 5-5
- #include <caml/fail.h>  // lines 3-3
- #include <caml/memory.h>  // lines 4-4
- #include <string.h>  // lines 9-9

The full include-list for src/ocaml_helpers.h:
#include <_string.h>        // for memcpy
#include <caml/custom.h>    // for custom_compare_default, custom_compare_ex...
#include <caml/mlvalues.h>  // for Data_custom_val, value, Field, Is_block
#include "binaryen-c.h"     // for BinaryenElementSegmentRef, BinaryenExportRef
#include "caml/misc.h"      // for CAMLprim
---

src/ocaml_helpers.c should add these lines:
#include <stddef.h>         // for NULL
#include "caml/custom.h"    // for caml_alloc_custom

src/ocaml_helpers.c should remove these lines:
- #include <caml/fail.h>  // lines 3-3

The full include-list for src/ocaml_helpers.c:
#include "ocaml_helpers.h"
#include <caml/callback.h>  // for caml_callback, caml_named_value
#include <caml/memory.h>    // for caml__roots_block, CAMLparam1, CAMLlocal1
#include <caml/mlvalues.h>  // for value, Int_val
#include <stddef.h>         // for NULL
#include "caml/custom.h"    // for caml_alloc_custom
---

src/op.c should add these lines:
#include "caml/misc.h"      // for CAMLprim

src/op.c should remove these lines:
- #include <caml/fail.h>  // lines 3-3

The full include-list for src/op.c:
#include <caml/memory.h>    // for caml__roots_block, CAMLparam1, CAMLreturn
#include <caml/mlvalues.h>  // for value
#include "binaryen-c.h"     // for BinaryenOp, BinaryenAbsFloat32, BinaryenA...
#include "caml/misc.h"      // for CAMLprim
#include "ocaml_helpers.h"  // for alloc_BinaryenOp
---

src/packed_type.c should add these lines:
#include "caml/misc.h"      // for CAMLprim

src/packed_type.c should remove these lines:
- #include <caml/fail.h>  // lines 3-3
- #include "ocaml_helpers.h"  // lines 7-7

The full include-list for src/packed_type.c:
#include <caml/memory.h>    // for caml__roots_block, CAMLparam1, CAMLreturn
#include <caml/mlvalues.h>  // for value, Val_int
#include "binaryen-c.h"     // for BinaryenPackedTypeInt16, BinaryenPackedTy...
#include "caml/misc.h"      // for CAMLprim
---

src/settings.c should add these lines:
#include <stdbool.h>        // for bool
#include <stddef.h>         // for NULL
#include "caml/misc.h"      // for CAMLprim

src/settings.c should remove these lines:
- #include <caml/fail.h>  // lines 4-4

The full include-list for src/settings.c:
#include <caml/alloc.h>     // for caml_alloc_some, caml_copy_string
#include <caml/memory.h>    // for caml__roots_block, CAMLreturn, CAMLparam1
#include <caml/mlvalues.h>  // for value, Val_unit, Val_bool, Bool_val, Int_val
#include <stdbool.h>        // for bool
#include <stddef.h>         // for NULL
#include "binaryen-c.h"     // for BinaryenAddPassToSkip, BinaryenAreColorsE...
#include "caml/misc.h"      // for CAMLprim
#include "ocaml_helpers.h"  // for Safe_String_val, Val_none
---

src/signature_type.c should add these lines:
#include "caml/misc.h"      // for CAMLprim

src/signature_type.c should remove these lines:
- #include <caml/fail.h>  // lines 3-3

The full include-list for src/signature_type.c:
#include <caml/memory.h>    // for caml__roots_block, CAMLparam1, CAMLreturn
#include <caml/mlvalues.h>  // for value
#include "binaryen-c.h"     // for BinaryenHeapType, BinaryenType, BinaryenS...
#include "caml/misc.h"      // for CAMLprim
#include "ocaml_helpers.h"  // for BinaryenHeapType_val, alloc_BinaryenType
---

src/struct_type.c should add these lines:
#include "caml/misc.h"      // for CAMLprim

src/struct_type.c should remove these lines:
- #include <caml/fail.h>  // lines 3-3

The full include-list for src/struct_type.c:
#include <caml/memory.h>    // for caml__roots_block, CAMLreturn, CAMLparam2
#include <caml/mlvalues.h>  // for value, Int_val, Val_int, Val_bool
#include "binaryen-c.h"     // for BinaryenHeapType, BinaryenIndex, Binaryen...
#include "caml/misc.h"      // for CAMLprim
#include "ocaml_helpers.h"  // for BinaryenHeapType_val, alloc_BinaryenType
---

src/table.c should add these lines:
#include "caml/misc.h"      // for CAMLprim

src/table.c should remove these lines:
- #include <caml/fail.h>  // lines 3-3

The full include-list for src/table.c:
#include <caml/alloc.h>     // for caml_copy_string
#include <caml/memory.h>    // for caml__roots_block, CAMLreturn, CAMLparam2
#include <caml/mlvalues.h>  // for value, Int_val, Val_unit, Val_int, Field
#include "binaryen-c.h"     // for BinaryenElementSegmentRef, BinaryenModuleRef
#include "caml/misc.h"      // for CAMLprim
#include "ocaml_helpers.h"  // for Safe_String_val, BinaryenElementSegmentRe...
---

src/tag.c should add these lines:
#include "caml/misc.h"      // for CAMLprim

src/tag.c should remove these lines:
- #include <caml/fail.h>  // lines 3-3

The full include-list for src/tag.c:
#include <caml/alloc.h>     // for caml_copy_string
#include <caml/memory.h>    // for caml__roots_block, CAMLreturn, CAMLparam1
#include <caml/mlvalues.h>  // for value, Val_unit
#include "binaryen-c.h"     // for BinaryenTagRef, BinaryenType, BinaryenMod...
#include "caml/misc.h"      // for CAMLprim
#include "ocaml_helpers.h"  // for BinaryenModuleRef_val, BinaryenTagRef_val
---

src/type.c should add these lines:
#include <stdbool.h>        // for bool
#include <stdlib.h>         // for free, malloc
#include "caml/alloc.h"     // for caml_alloc
#include "caml/misc.h"      // for CAMLprim

src/type.c should remove these lines:
- #include <caml/fail.h>  // lines 3-3

The full include-list for src/type.c:
#include <caml/memory.h>    // for caml__roots_block, CAMLreturn, CAMLparam1
#include <caml/mlvalues.h>  // for value, Field, Bool_val, Val_bool
#include <stdbool.h>        // for bool
#include <stdlib.h>         // for free, malloc
#include "binaryen-c.h"     // for BinaryenType, BinaryenHeapType, BinaryenT...
#include "caml/alloc.h"     // for caml_alloc
#include "caml/misc.h"      // for CAMLprim
#include "ocaml_helpers.h"  // for alloc_BinaryenType, BinaryenType_val, Bin...
---

src/ocaml_helpers.h should add these lines:
#include <_string.h>        // for memcpy
#include "caml/misc.h"      // for CAMLprim

src/ocaml_helpers.h should remove these lines:
- #include <caml/alloc.h>  // lines 6-6
- #include <caml/callback.h>  // lines 5-5
- #include <caml/fail.h>  // lines 3-3
- #include <caml/memory.h>  // lines 4-4
- #include <string.h>  // lines 9-9

The full include-list for src/ocaml_helpers.h:
#include <_string.h>        // for memcpy
#include <caml/custom.h>    // for custom_compare_default, custom_compare_ex...
#include <caml/mlvalues.h>  // for value, Data_custom_val, Field, Is_block
#include "binaryen-c.h"     // for BinaryenElementSegmentRef, BinaryenExportRef
#include "caml/misc.h"      // for CAMLprim
---

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.

1 participant