Skip to content

BorrowChecker: opt-in + @safe annotations for node copy/preallocation#158

Closed
MilesCranmerBot wants to merge 9 commits intoSymbolicML:masterfrom
MilesCranmerBot:bot/borrow-checker-sweep-2026-02-01
Closed

BorrowChecker: opt-in + @safe annotations for node copy/preallocation#158
MilesCranmerBot wants to merge 9 commits intoSymbolicML:masterfrom
MilesCranmerBot:bot/borrow-checker-sweep-2026-02-01

Conversation

@MilesCranmerBot
Copy link
Contributor

@MilesCranmerBot MilesCranmerBot commented Feb 2, 2026

This PR integrates BorrowChecker as an opt-in safety layer (disabled by default), and annotates the core node copy/preallocation routines with BorrowChecker.@safe (plus a few @unsafe blocks where needed).

Key changes:

  • Add BorrowChecker opt-in hooks (disabled by default via preferences).
  • Mark allocate_container, copy_into!, leaf_copy_into!, branch_copy_into!, leaf_copy, branch_copy, and copy_node as @safe.
  • Run JuliaFormatter.

Local testing (borrow checker enabled via LocalPreferences.toml):

  • Julia 1.12.0: Pkg.test("DynamicExpressions")

@MilesCranmerBot MilesCranmerBot force-pushed the bot/borrow-checker-sweep-2026-02-01 branch from 7f5a283 to c670472 Compare February 2, 2026 00:24
@github-actions
Copy link
Contributor

github-actions bot commented Feb 2, 2026

Benchmark Results (Julia v1)

Time benchmarks
master c670472... master / c670472...
eval/ComplexF32/evaluation 6.86 ± 0.49 ms 6.97 ± 0.52 ms 0.984 ± 0.1
eval/ComplexF64/evaluation 10.2 ± 0.76 ms 10.4 ± 1.3 ms 0.981 ± 0.14
eval/Float32/derivative 11 ± 0.77 ms 12.5 ± 1.9 ms 0.883 ± 0.15
eval/Float32/derivative_turbo 11.2 ± 0.95 ms 12.2 ± 1.9 ms 0.915 ± 0.16
eval/Float32/evaluation 2.44 ± 0.24 ms 2.48 ± 0.26 ms 0.982 ± 0.14
eval/Float32/evaluation_bumper 0.568 ± 0.016 ms 0.604 ± 0.019 ms 0.94 ± 0.039
eval/Float32/evaluation_turbo 0.503 ± 0.025 ms 0.545 ± 0.036 ms 0.924 ± 0.076
eval/Float32/evaluation_turbo_bumper 0.567 ± 0.015 ms 0.607 ± 0.021 ms 0.934 ± 0.041
eval/Float64/derivative 14 ± 0.67 ms 15.5 ± 0.85 ms 0.906 ± 0.066
eval/Float64/derivative_turbo 14 ± 0.65 ms 15.5 ± 0.78 ms 0.909 ± 0.063
eval/Float64/evaluation 2.91 ± 0.3 ms 2.94 ± 0.32 ms 0.993 ± 0.15
eval/Float64/evaluation_bumper 1.19 ± 0.041 ms 1.26 ± 0.045 ms 0.941 ± 0.047
eval/Float64/evaluation_turbo 1.02 ± 0.069 ms 1.04 ± 0.064 ms 0.98 ± 0.09
eval/Float64/evaluation_turbo_bumper 1.18 ± 0.041 ms 1.26 ± 0.046 ms 0.937 ± 0.047
utils/combine_operators/break_sharing 0.041 ± 0.0017 ms 0.0417 ± 0.002 ms 0.983 ± 0.062
utils/convert/break_sharing 27.1 ± 3.2 μs 27.7 ± 3.1 μs 0.98 ± 0.16
utils/convert/preserve_sharing 0.098 ± 0.0072 ms 0.0991 ± 0.0085 ms 0.989 ± 0.11
utils/copy/break_sharing 27.2 ± 2.7 μs 26.9 ± 2.8 μs 1.01 ± 0.15
utils/copy/preserve_sharing 0.0989 ± 0.0078 ms 0.0988 ± 0.0075 ms 1 ± 0.11
utils/count_constant_nodes/break_sharing 12.6 ± 0.77 μs 13 ± 1.4 μs 0.966 ± 0.12
utils/count_constant_nodes/preserve_sharing 0.0839 ± 0.0062 ms 0.084 ± 0.0067 ms 0.999 ± 0.11
utils/count_depth/break_sharing 13.8 ± 1 μs 13.9 ± 0.93 μs 0.992 ± 0.098
utils/count_nodes/break_sharing 12.2 ± 0.84 μs 12.6 ± 0.72 μs 0.965 ± 0.087
utils/count_nodes/preserve_sharing 0.0848 ± 0.0059 ms 0.0834 ± 0.0047 ms 1.02 ± 0.091
utils/get_set_constants!/break_sharing 0.0324 ± 0.0035 ms 0.0328 ± 0.0029 ms 0.988 ± 0.14
utils/get_set_constants!/preserve_sharing 0.172 ± 0.0093 ms 0.172 ± 0.0094 ms 0.996 ± 0.076
utils/get_set_constants_parametric 0.0462 ± 0.0051 ms 0.046 ± 0.0049 ms 1 ± 0.15
utils/has_constants/break_sharing 7.31 ± 0.69 μs 7.38 ± 0.71 μs 0.991 ± 0.13
utils/has_operators/break_sharing 2.6 ± 0.23 μs 2.6 ± 0.14 μs 1 ± 0.1
utils/hash/break_sharing 24.2 ± 1.4 μs 23.5 ± 1.2 μs 1.03 ± 0.08
utils/hash/preserve_sharing 0.099 ± 0.0061 ms 0.0993 ± 0.0071 ms 0.996 ± 0.094
utils/index_constant_nodes/break_sharing 29 ± 2.2 μs 29.8 ± 2 μs 0.974 ± 0.1
utils/index_constant_nodes/preserve_sharing 0.0991 ± 0.0066 ms 0.0992 ± 0.006 ms 0.999 ± 0.09
utils/is_constant/break_sharing 7.92 ± 0.8 μs 7.96 ± 0.73 μs 0.994 ± 0.14
utils/simplify_tree/break_sharing 30.7 ± 1.2 μs 29.3 ± 1.1 μs 1.05 ± 0.055
utils/simplify_tree/preserve_sharing 0.111 ± 0.0064 ms 0.111 ± 0.005 ms 1 ± 0.073
utils/string_tree/break_sharing 0.438 ± 0.017 ms 0.434 ± 0.018 ms 1.01 ± 0.057
utils/string_tree/preserve_sharing 0.541 ± 0.021 ms 0.531 ± 0.023 ms 1.02 ± 0.059
time_to_load 0.166 ± 0.00019 s 0.223 ± 0.0042 s 0.742 ± 0.014
Memory benchmarks
master c670472... master / c670472...
eval/ComplexF32/evaluation 0.975 k allocs: 2.5 MB 0.963 k allocs: 2.46 MB 1.01
eval/ComplexF64/evaluation 0.996 k allocs: 5.07 MB 0.969 k allocs: 4.94 MB 1.03
eval/Float32/derivative 4.66 k allocs: 17.5 MB 4.64 k allocs: 17.5 MB 1
eval/Float32/derivative_turbo 4.69 k allocs: 17.7 MB 4.66 k allocs: 17.6 MB 1.01
eval/Float32/evaluation 0.966 k allocs: 1.26 MB 0.996 k allocs: 1.3 MB 0.97
eval/Float32/evaluation_bumper 0.303 k allocs: 0.393 MB 0.303 k allocs: 0.393 MB 1
eval/Float32/evaluation_turbo 0.969 k allocs: 1.26 MB 0.966 k allocs: 1.26 MB 1
eval/Float32/evaluation_turbo_bumper 0.303 k allocs: 0.393 MB 0.303 k allocs: 0.393 MB 1
eval/Float64/derivative 4.77 k allocs: 0.0349 GB 4.76 k allocs: 0.0348 GB 1
eval/Float64/derivative_turbo 4.77 k allocs: 0.0349 GB 4.77 k allocs: 0.0349 GB 0.999
eval/Float64/evaluation 0.999 k allocs: 2.56 MB 1 k allocs: 2.57 MB 0.997
eval/Float64/evaluation_bumper 0.303 k allocs: 0.771 MB 0.303 k allocs: 0.771 MB 1
eval/Float64/evaluation_turbo 0.987 k allocs: 2.53 MB 0.978 k allocs: 2.5 MB 1.01
eval/Float64/evaluation_turbo_bumper 0.303 k allocs: 0.771 MB 0.303 k allocs: 0.771 MB 1
utils/combine_operators/break_sharing 4 allocs: 0.953 kB 4 allocs: 0.953 kB 1
utils/convert/break_sharing 2 k allocs: 0.123 MB 2 k allocs: 0.123 MB 1
utils/convert/preserve_sharing 2.4 k allocs: 0.192 MB 2.4 k allocs: 0.192 MB 1
utils/copy/break_sharing 2 k allocs: 0.123 MB 2 k allocs: 0.123 MB 1
utils/copy/preserve_sharing 2.4 k allocs: 0.192 MB 2.4 k allocs: 0.192 MB 1
utils/count_constant_nodes/break_sharing 4 allocs: 0.953 kB 4 allocs: 0.953 kB 1
utils/count_constant_nodes/preserve_sharing 0.404 k allocs: 0.0696 MB 0.404 k allocs: 0.0696 MB 1
utils/count_depth/break_sharing 4 allocs: 0.953 kB 4 allocs: 0.953 kB 1
utils/count_nodes/break_sharing 4 allocs: 0.953 kB 4 allocs: 0.953 kB 1
utils/count_nodes/preserve_sharing 0.404 k allocs: 0.0696 MB 0.404 k allocs: 0.0696 MB 1
utils/get_set_constants!/break_sharing 0.898 k allocs: 25.2 kB 0.898 k allocs: 25.2 kB 1
utils/get_set_constants!/preserve_sharing 1.7 k allocs: 0.138 MB 1.7 k allocs: 0.138 MB 1
utils/get_set_constants_parametric 1.42 k allocs: 0.0663 MB 1.42 k allocs: 0.0663 MB 1
utils/has_constants/break_sharing 4 allocs: 0.203 kB 4 allocs: 0.203 kB 1
utils/has_operators/break_sharing 4 allocs: 0.203 kB 4 allocs: 0.203 kB 1
utils/hash/break_sharing 0.104 k allocs: 2.52 kB 0.104 k allocs: 2.52 kB 1
utils/hash/preserve_sharing 0.504 k allocs: 0.0711 MB 0.504 k allocs: 0.0711 MB 1
utils/index_constant_nodes/break_sharing 2.1 k allocs: 0.094 MB 2.1 k allocs: 0.094 MB 1
utils/index_constant_nodes/preserve_sharing 2.5 k allocs: 0.163 MB 2.5 k allocs: 0.163 MB 1
utils/is_constant/break_sharing 4 allocs: 0.203 kB 4 allocs: 0.203 kB 1
utils/simplify_tree/break_sharing 0.104 k allocs: 2.52 kB 0.104 k allocs: 2.52 kB 1
utils/simplify_tree/preserve_sharing 0.504 k allocs: 0.0711 MB 0.504 k allocs: 0.0711 MB 1
utils/string_tree/break_sharing 11.9 k allocs: 0.999 MB 11.9 k allocs: 0.999 MB 1
utils/string_tree/preserve_sharing 12.3 k allocs: 1.07 MB 12.3 k allocs: 1.07 MB 1
time_to_load 0.145 k allocs: 11 kB 0.145 k allocs: 11 kB 1

@codecov
Copy link

codecov bot commented Feb 2, 2026

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 96.70%. Comparing base (95541e7) to head (c670472).

Additional details and impacted files
@@            Coverage Diff             @@
##           master     #158      +/-   ##
==========================================
+ Coverage   96.65%   96.70%   +0.04%     
==========================================
  Files          30       30              
  Lines        2634     2639       +5     
==========================================
+ Hits         2546     2552       +6     
+ Misses         88       87       -1     

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

@MilesCranmer
Copy link
Member

This sort of thing requires more thought first, closing for now.

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.

2 participants