Commit graph

1109 commits

Author SHA1 Message Date
Cameron Zwarich
91a2de1e1e
chore: use forallTelescope rather than forallTelescopeReducing (#10073) 2025-08-23 04:07:23 +00:00
Cameron Zwarich
4a7def9e5f
chore: use Expr.fvarId! and FVarId.getType (#10072) 2025-08-23 04:04:57 +00:00
Cameron Zwarich
dc5766d27a
fix: eliminate infinite loop in toLCNF's expandNoConfusionMajor (#10070)
This PR fixes the compilation of `noConfusion` by repairing an oversight
made when porting this code from the old compiler. The old compiler only
repeatedly expanded the major for each non-`Prop` field of the inductive
under consideration, mirroring the construction of `noConfusion` itself,
whereas the new compiler erroneously counted all fields.

Fixes #9971.
2025-08-23 02:18:51 +00:00
Jason Yuen
facc356a0a
chore: fix spelling errors (#10042)
Typos were found with
```
pip install codespell --upgrade
codespell --summary --ignore-words-list enew,forin,fro,happend,hge,ihs,iterm,spred --skip stage0 --check-filenames
codespell --summary --ignore-words-list enew,forin,fro,happend,hge,ihs,iterm,spred --skip stage0 --check-filenames --regex '[A-Z][a-z]*'
codespell --summary --ignore-words-list enew,forin,fro,happend,hge,ihs,iterm,spred --skip stage0 --check-filenames --regex "\b[a-z']*"
```
2025-08-22 07:23:12 +00:00
Cameron Zwarich
5aa706435a
fix: incorporate info from _redArg decls for noncomputable check (#10040)
This PR changes the `toMono` pass to replace decls with their `_redArg`
equivalent, which has the consequence of not considering arguments
deemed useless by the `reduceArity` pass for the purposes of the
`noncomputable` check.
2025-08-22 01:02:40 +00:00
Cameron Zwarich
504d71f268
chore: remove unnecessary code handling cases of an erased value (#10035)
This is now all handled in `toLCNF`.
2025-08-21 21:55:10 +00:00
Cameron Zwarich
ca4322ff09
fix: support casesOn for inductive predicates with computations on fields (#10023)
This PR adds support for correctly handling computations on fields in
`casesOn` for inductive predicates that support large elimination. In
any such predicate, the only relevant fields allowed are those that are
also used as an index, in which case we can find the supplied index and
use that term instead.
2025-08-21 18:55:34 +00:00
Cameron Zwarich
0c9bb4b861
fix: lower overapplied constructors to unreachable (#10032)
This PR changes the handling of overapplied constructors when lowering
LCNF to IR from a (slightly implicit) assertion failure to producing
`unreachable`. Transformations on inlined unreachable code can produce
constructor applications with additional arguments.

In the old compiler, these additional arguments were silently ignored,
but it seems more sensible to replace them with `unreachable`, just in
case they arise due to a compiler error.

Fixes #9937.
2025-08-21 15:05:09 +00:00
Cameron Zwarich
d6a43a660f
perf: disable reuse when a value's last use is an owned argument (#10017)
The current reuse analysis is greedy in that every function attempts to
reuse a value. However, this means that if the last use is an owned
argument, it will be `inc`'d prior to this last use, in order to prevent
reuse from happening in the callee. In many cases, it makes more sense
to give the callee the chance to reuse it instead. The benchmark results
indicate that this is a much better default.
2025-08-21 00:41:56 +00:00
Cameron Zwarich
8536fe5aa9
refactor: split handling of normal fvars and join points in toIR (#9981)
This makes the representation of lowered fvar values the IR `Arg` type.
2025-08-19 03:44:15 +00:00
Cameron Zwarich
b68f3455d3
refactor: use a separate getter for fvar values in toIR (#9978) 2025-08-19 01:28:15 +00:00
Cameron Zwarich
89752e2242
fix: support compiling casesOn recursors of subsingleton predicates (#9977)
This PR adds support for compilation of `casesOn` recursors of
subsingleton predicates.

Fixes #9963.
2025-08-19 00:23:24 +00:00
Cameron Zwarich
b8fa6f17ee
fix: make lcAny-producing arrow types lower to tobj rather than obj (#9972)
This PR fixes an issue when running Mathlib's `FintypeCat` as code,
where an erased type former is passed to a polymorphic function. We were
lowering the arrow type to`object`, which conflicts with the runtime
representation of an erased value as a tagged scalar.
2025-08-18 22:18:26 +00:00
Cameron Zwarich
0e968f010a
chore: fix indentation (#9936) 2025-08-16 05:30:36 +00:00
Cameron Zwarich
05c1ba291d
fix: erase dependencies on let-bound fvars in internalizeCode (#9922)
This PR changes `internalizeCode` to replace all substitutions with
non-param-bound fvars in `Expr`s (which are all types) with `lcAny`,
preserving the invariant that there are no such dependencies. The
violation of this invariant across files caused test failures in a
pending PR, but it is difficult to write a direct test for it. In the
future, we should probably change the LCNF checker to detect this.

This change also speeds up some compilation-heavy benchmarks much more
than I would've expected, which is a pleasant surprise. This indicates
we might get more speedups from reducing the amount of type information
we preserve in LCNF.
2025-08-15 01:52:47 +00:00
Sebastian Ullrich
ddfeca1b1b
fix: do not allow access to private primitives in public scope (#9890)
This PR addresses a missing check in the module system where private
names that remain in the public environment map for technical reasons
(e.g. inductive constructors generated by the kernel and relied on by
the code generator) accidentally were accessible in the public scope.
2025-08-14 15:34:54 +00:00
Sebastian Ullrich
1ba1424ac3
perf: local metaExt (#9822) 2025-08-14 14:26:12 +00:00
Sebastian Ullrich
640337e0a0
chore: error on [macro_inline] without [expose] (#9891) 2025-08-13 10:57:48 +00:00
Cameron Zwarich
639baaaa03
refactor: adopt do notation (#9882) 2025-08-12 22:12:59 +00:00
Cameron Zwarich
6f7ca5e5d3
refactor: take more advantage of anonymous constructors (#9881) 2025-08-12 21:19:40 +00:00
Cameron Zwarich
e9df183e87
perf: avoid ref count increments for borrowed array accesses (#9866) 2025-08-12 05:27:35 +00:00
Cameron Zwarich
bf348ae60f
refactor: use more helper functions (#9862) 2025-08-11 23:56:50 +00:00
Cameron Zwarich
ca05569cd5
refactor: rename VarProjInfo to DerivedValInfo (#9859)
We want to use this for non-projections in the near future.
2025-08-11 22:02:28 +00:00
Cameron Zwarich
5b5bb5174b
fix: check for recursive decls before instance proj inlining (#9847)
This PR adds a check for reursive decls in this bespoke inlining path,
which fixes a regression from the old compiler.

Fixes #9624.
2025-08-11 13:50:26 +00:00
Cameron Zwarich
4506173a27
fix: support overapplication of Quot.lift in the compiler (#9827)
This PR changes the lowering of `Quot.lcInv` (the compiler-internal form
of `Quot.lift`) in `toMono` to support overapplication.

Fixes #9806.
2025-08-11 01:51:54 +00:00
Cameron Zwarich
544f9912b7
chore: add separate profiling entries for base, mono, and IR phases (#9817) 2025-08-10 05:00:49 +00:00
Cameron Zwarich
361ca788a7
refactor: split the LCNF pass list into separate base/mono lists (#9816)
This will make it easier to run the two phases in parallel.
2025-08-10 04:23:19 +00:00
Cameron Zwarich
756f837f82
perf: reduce redundant inc/dec using "implied borrows" from projections and liveness (#9801)
This PR changes the IR RC pass to take "implied borrows" from
projections into account. If a projected value's lifetime is contained
in that of its parent (or any projection ancestor), then it does not
need its reference count incremented (or later decremented).

I believe that this same technique should generalize to both the
reset/reuse and borrow signature inference passes.
2025-08-09 14:13:50 +00:00
Cameron Zwarich
2104fd7da9
chore: remove unused default (#9791) 2025-08-07 16:27:23 +00:00
Cameron Zwarich
a2f24fac65
chore: use unreachable! for unreachable cases, not silent fallback (#9790) 2025-08-07 15:23:01 +00:00
Cameron Zwarich
eaec888dc3
refactor: add isPossibleRef/isDefiniteRef fields to RC VarInfo (#9789)
These are the only uses of the existing `type` field, so we might as
well compute them up-front and store them.
2025-08-07 14:21:19 +00:00
Cameron Zwarich
aaf831cd93
perf: don't mark params stored in tagged pointers as borrowed (#9775) 2025-08-07 03:49:23 +00:00
Cameron Zwarich
472a0b4954
refactor: invert and rename RC VarInfo.mustBeConsumed to .inheritsBorrowFromParam (#9777) 2025-08-07 02:04:12 +00:00
Cameron Zwarich
c04323a7d5
perf: use a slightly more refined borrowed param test in RC pass (#9774) 2025-08-07 01:08:32 +00:00
Cameron Zwarich
fac4905e89
chore: fix function body indentation (#9773) 2025-08-07 00:44:43 +00:00
Cameron Zwarich
f23d24ec7c
perf: avoid computing liveness twice for cases in RC pass (#9770) 2025-08-06 18:54:58 +00:00
Cameron Zwarich
e332adf3d5
perf: avoid computing liveness twice for join point decls in RC pass (#9768)
We compute the liveness information for the join point body, so the only
thing that updateJPLiveVarMap should be adding is the binding of the
params, which we can easily do ourselves.

If we supported recursive join points, I believe this would actually be
a correctness issue, but as-is it doesn't affect the output.
2025-08-06 17:34:29 +00:00
Cameron Zwarich
f759d5dbc1
perf: erase all constructor params in the mono phase (#9764) 2025-08-06 14:23:28 +00:00
Cameron Zwarich
d8c7c9fdb5
refactor: reduce code duplication (#9753) 2025-08-06 05:38:10 +00:00
Cameron Zwarich
885b8bcc60
chore: inline a function into its only caller (#9750) 2025-08-06 03:47:38 +00:00
Cameron Zwarich
31e05cd2bd
chore: fix typos (#9747) 2025-08-06 00:49:49 +00:00
Cameron Zwarich
7fb72a0081
refactor: rename RC VarInfo.consume field to .mustBeConsumed (#9746) 2025-08-06 00:48:10 +00:00
Cameron Zwarich
51b780cd9f
chore: rewrite LiveVars in a monadic style (#9745) 2025-08-05 21:49:43 +00:00
Cameron Zwarich
25b0c5af34
chore: don't match on Context (#9744) 2025-08-05 21:32:34 +00:00
Cameron Zwarich
6846a5179b
chore: reduce code duplication (#9742) 2025-08-05 20:42:56 +00:00
Cameron Zwarich
eb5399445a
chore: clean up parens (#9740) 2025-08-05 18:21:38 +00:00
Cameron Zwarich
83c08880a6
chore: use dotted constructor names (#9738) 2025-08-05 17:17:06 +00:00
Cameron Zwarich
172a02557e
chore: clean up uses of getters (#9737) 2025-08-05 16:48:35 +00:00
Cameron Zwarich
ed860dfa23
chore: use better struct literal syntax (#9731) 2025-08-05 14:07:39 +00:00
Cameron Zwarich
12cd4ca742
fix: remove incorrect error in LCNF's check (#9720)
This PR removes an error which implicitly assumes that the sort of type
dependency between erased types present in the test being added can not
occur. It would be difficult to refine the error using only the
information present in LCNF types, and it is of very little ongoing
value (I don't recall it ever finding an actual problem), so it makes
more sense to delete it.

Fixes #9692.
2025-08-05 04:36:57 +00:00