Skip to content

Miscellaneous type inferability fixes#1313

Draft
Antoinemarteau wants to merge 33 commits into
masterfrom
type-inferrable-array_cache
Draft

Miscellaneous type inferability fixes#1313
Antoinemarteau wants to merge 33 commits into
masterfrom
type-inferrable-array_cache

Conversation

@Antoinemarteau

@Antoinemarteau Antoinemarteau commented Jun 4, 2026

Copy link
Copy Markdown
Collaborator

We have been looking at making array_cache type inferrable to avoid dynamic dispatches on getindex! #1303. This require all nested array_cache and return_cache present in the LazyArrays' operation tree to be inferrable.

This PR fixes many type inferrability failures in Gridap and its tests, should be mergable without breaking anything.

I find them using the new @check_inferred macro, that uses Base.@inferred to detect them in "debug" mode only.
Not many checks are added here cause they break too much stuff, I use this branch to find them, it also contains WIP alternative fix to #1303.

TODO: these are type un-inferrable maps I didn't fix yet, that end up in lazy array cache in the tests:

(there will be more, I did'nt finish scanning MultiField and Adaptivity).

placed a couple of them in order to catch type instability due to user
given analytical functions
fixed inferability issues in DiffOperatorsTests.jl
captured global variables needed to be fixed in let blocks for type
inference
size of values was wrong for Vector V
- composed OperationField
- composed auto-diffed functions
- Using Base.Fix as the idiomatic Julia way to ensure sepializing on
  clojured functions
This caused an issue when composed with `get_polytope(reffe)` which is
not type stable. Anotating the return type makes `get_dimrange` type
stable anyway.
for models with type-unstable `get_grid_topology`, such as
    DiscreteModelPortion struct that has abstract fields, these would
    not be infered, nor "constantly unfolded" at compile type.

Instead, I fall back to Grid's default API
when get_grid_topology is not type stable on model, this in necessary
for inferrability of return_cache(::NormalSignMap).

A better fix would be to concretely type all DiscreteModel (the one that
triggered this is DiscreteModelPortion).
apparently, this is necessary for inferrability when there's a Diagonal
value input (was triggered in ReferenceFEs/RaviartThomasRefRETests
@codecov

codecov Bot commented Jun 4, 2026

Copy link
Copy Markdown

Codecov Report

❌ Patch coverage is 86.77686% with 16 lines in your changes missing coverage. Please review.
✅ Project coverage is 88.76%. Comparing base (cc85d45) to head (270904a).
⚠️ Report is 10 commits behind head on master.

Files with missing lines Patch % Lines
src/Helpers/Macros.jl 46.15% 14 Missing ⚠️
src/Fields/FieldsInterfaces.jl 95.65% 1 Missing ⚠️
src/ReferenceFEs/GeneralPolytopes.jl 0.00% 1 Missing ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##           master    #1313      +/-   ##
==========================================
- Coverage   88.86%   88.76%   -0.10%     
==========================================
  Files         228      228              
  Lines       30183    30200      +17     
==========================================
- Hits        26821    26807      -14     
- Misses       3362     3393      +31     
Flag Coverage Δ
drivers 39.35% <50.50%> (-0.01%) ⬇️
extensions 5.00% <0.00%> (+<0.01%) ⬆️
unit-adaptivity 39.97% <28.28%> (-0.01%) ⬇️
unit-basics 14.42% <21.48%> (+0.03%) ⬆️
unit-celldata 20.78% <30.30%> (-0.06%) ⬇️
unit-fespaces-1 32.60% <33.33%> (-0.01%) ⬇️
unit-fespaces-2 39.32% <46.46%> (-0.02%) ⬇️
unit-fields 17.47% <52.52%> (+0.01%) ⬆️
unit-geometry 28.36% <23.23%> (-0.01%) ⬇️
unit-multifield 30.42% <28.28%> (-0.01%) ⬇️
unit-odes 28.31% <30.30%> (-0.01%) ⬇️
unit-referencefes 33.84% <33.33%> (-0.04%) ⬇️
unit-visualization 11.65% <4.04%> (-0.02%) ⬇️

Flags with carried forward coverage won't be shown. Click here to find out more.

☔ View full report in Codecov by Harness.
📢 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.

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