Skip to content

Remove dependency on Core in favor of small wrapper around Base - #1643

Merged
WardBrian merged 4 commits into
masterfrom
drop-core
Jul 12, 2026
Merged

Remove dependency on Core in favor of small wrapper around Base#1643
WardBrian merged 4 commits into
masterfrom
drop-core

Conversation

@WardBrian

@WardBrian WardBrian commented Jul 10, 2026

Copy link
Copy Markdown
Member

This should resolve #1640.

To make the patch as minimal as possible, I added our own Core.ml module which shadows all the open Cores we have, which just uses base and a few other small changes for compatibility. This means we could rather seamlessly return to using core once 0.18 (which removed the weird Temporal polyfill) is released, if we wished

Submission Checklist

  • Run unit tests
  • Documentation
    • If a user-facing facing change was made, the documentation PR is here:
    • OR, no user-facing changes were made

Release notes

Replace this text with a short note on what will change if this pull request is merged. This will be included in the release notes.

Copyright and Licensing

By submitting this pull request, the copyright holder is agreeing to
license the submitted work under the BSD 3-clause license (https://opensource.org/licenses/BSD-3-Clause)

@WardBrian
WardBrian marked this pull request as ready for review July 10, 2026 19:50
@WardBrian
WardBrian requested review from andrjohns and nhuurre July 10, 2026 19:51

@nhuurre nhuurre left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

The other PR had several files where the only change is open Core -> open Base. If a file doesn't need anything from Core then don't open Core.

Comment thread docs/dependencies.mld Outdated
Comment thread src/core/Core.ml Outdated
Comment thread src/core/Core.ml
Comment on lines +90 to +98
let ( ^^ ) = Stdlib.( ^^ )
let ( ** ) = Stdlib.( ** )
let string_of_int = Stdlib.string_of_int
let int_of_string = Stdlib.int_of_string
let int_of_string_opt = Stdlib.int_of_string_opt
let float_of_string = Stdlib.float_of_string
let float_of_string_opt = Stdlib.float_of_string_opt
let float_of_int = Stdlib.float_of_int
let exit = Stdlib.exit

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

I'd rather not add these.

  • we already use Int.to_string, Int.of_string, and Float.of_string in some places. It's more consistent to use those everywhere instead of sometimes calling Stdlib.string_of_int etc.
  • (^^), (**), int_of_string_opt, float_of_string_opt, and exit are only used once each so defining them here doesn't reduce the diff. (Also if we're using Float.of_string then maybe we should use Float.of_string_opt instead of Stdlib.float_of_string_opt. Is there any difference between those?)
  • that leaves only float_of_int but it's not that much work to change it to Float.of_int, there's only four calls.

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

I'm happy to replace the _to_/_of_ with the module versions, but I'd rather leave ^^/**/exit -- I think shadowing such basic functionality in the standard library is a dumb move on Base's part, which I suspect at least someone at JS agrees with since they don't do it in Core, despite re-exporting everything else in Base

Comment on lines +9 to +10
module Expr_set = struct
type t = Set.M(Expr.Typed).t

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

If the idea is to minimize the diff, shouldn't this module be inside Expr.Typed? Is there a reason it has to be defined here?

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

It doesn't have to be, but this is the only file that actually used it, and writing down the signature in Expr.mli was a bit verbose/annoying

Comment thread src/middle/Operator.ml
@WardBrian

Copy link
Copy Markdown
Member Author

I'd also rather audit whether Core needs to be opened at the top of files in a separate PR, because I suspect the Stdlib improvements in OCaml 5 actually mean a lot of our files don't need Core or Base any longer, but that's a more involved project

@codecov

codecov Bot commented Jul 10, 2026

Copy link
Copy Markdown

Codecov Report

❌ Patch coverage is 92.42424% with 5 lines in your changes missing coverage. Please review.
✅ Project coverage is 91.48%. Comparing base (8b53394) to head (971a975).

Files with missing lines Patch % Lines
...analysis_and_optimization/Debug_data_generation.ml 60.00% 2 Missing ⚠️
...rc/analysis_and_optimization/Monotone_framework.ml 89.47% 2 Missing ⚠️
src/frontend/Deprecation_analysis.ml 50.00% 1 Missing ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##           master    #1643      +/-   ##
==========================================
+ Coverage   91.44%   91.48%   +0.04%     
==========================================
  Files          66       67       +1     
  Lines        9978    10009      +31     
==========================================
+ Hits         9124     9157      +33     
+ Misses        854      852       -2     
Files with missing lines Coverage Δ
src/analysis_and_optimization/Factor_graph.ml 73.27% <ø> (+2.33%) ⬆️
src/analysis_and_optimization/Mir_utils.ml 77.93% <100.00%> (ø)
src/analysis_and_optimization/Optimize.ml 93.67% <100.00%> (+0.02%) ⬆️
src/analysis_and_optimization/Partial_evaluator.ml 90.93% <100.00%> (+0.06%) ⬆️
src/core/Core.ml 100.00% <100.00%> (ø)
src/frontend/Ast_to_Mir.ml 96.00% <100.00%> (ø)
src/frontend/Parse.ml 100.00% <100.00%> (ø)
src/frontend/Preprocessor.ml 98.61% <100.00%> (ø)
src/frontend/SignatureMismatch.ml 87.86% <100.00%> (+0.08%) ⬆️
src/frontend/Typechecker.ml 94.87% <ø> (ø)
... and 13 more

... and 6 files with indirect coverage changes

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

@hhugo

hhugo commented Jul 11, 2026

Copy link
Copy Markdown

How does this PR affects the size of the stanc.js file ?

@andrjohns

andrjohns commented Jul 11, 2026

Copy link
Copy Markdown
Contributor

How does this PR affects the size of the stanc.js file ?

A pretty decent amount: ~6mb reduction in unminified/debug bundle, ~700kb reduction in minified/release

@WardBrian
WardBrian requested a review from nhuurre July 11, 2026 12:59
@hhugo

hhugo commented Jul 11, 2026

Copy link
Copy Markdown

I

How does this PR affects the size of the stanc.js file ?

A pretty decent amount: ~6mb reduction in unminified/debug bundle, ~700kb reduction in minified/release

And in percentage ?

Comment thread src/core/dune
@@ -0,0 +1,6 @@
(library
(name core)

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

This name probaby mean it wont be able to link together with core. I dont know if its an issue for you here

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

This was a feature to me, since it meant I couldn’t accidentally pull it back in somewhere :)

I am intending this to be a temporary solution to unblock our downstream projects before doing a more serious audit of whether we even really need Base. Stdlib has gotten quite a lot better in 5.x as far as I can tell

@WardBrian

Copy link
Copy Markdown
Member Author

And in percentage ?

~15% reduction

@WardBrian
WardBrian merged commit 9247c1d into master Jul 12, 2026
3 checks passed
@WardBrian
WardBrian deleted the drop-core branch July 12, 2026 14:26
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.

Ocaml 5.5 upgrade introduced Intl dependency into stanc.js - breaking quickjs

4 participants