Skip to content

Add Core-to-Core function inlining transforms#1007

Open
tautschnig wants to merge 2 commits intomainfrom
tautschnig/function-inlining
Open

Add Core-to-Core function inlining transforms#1007
tautschnig wants to merge 2 commits intomainfrom
tautschnig/function-inlining

Conversation

@tautschnig
Copy link
Copy Markdown
Contributor

Add function inlining transforms in Strata/Transform/FunctionInlining.lean:

  • inlineFuncDefs: replace non-recursive function calls with their bodies, with optional postProcess hook for composing with other transforms
  • collectFuncDefs: collect non-recursive function definitions
  • inlineRecFuncDefs: bounded unrolling of recursive function calls

These operate at the expression level (pure function applications), complementing the existing ProcedureInlining which operates at the statement level (imperative procedure calls).

By submitting this pull request, I confirm that you can use, modify, copy, and redistribute this contribution, under the terms of your choice.

Add function inlining transforms in Strata/Transform/FunctionInlining.lean:
- inlineFuncDefs: replace non-recursive function calls with their bodies,
  with optional postProcess hook for composing with other transforms
- collectFuncDefs: collect non-recursive function definitions
- inlineRecFuncDefs: bounded unrolling of recursive function calls

These operate at the expression level (pure function applications),
complementing the existing ProcedureInlining which operates at the
statement level (imperative procedure calls).

Co-authored-by: Kiro <kiro-agent@users.noreply.github.com>
Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull request overview

Adds a new Core-to-Core transform module for inlining pure function applications at the expression level, complementing existing statement-level procedure inlining.

Changes:

  • Introduces inlineFuncDefs for inlining fully-applied non-recursive functions with an optional postProcess hook.
  • Adds collectFuncDefs to extract eligible (non-recursive, monomorphic) function bodies from a Core.Program.
  • Introduces inlineRecFuncDefs for bounded unrolling of recursive function calls.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment thread Strata/Transform/FunctionInlining.lean Outdated
Comment thread Strata/Transform/FunctionInlining.lean Outdated
Comment thread Strata/Transform/FunctionInlining.lean Outdated
Comment thread Strata/Transform/FunctionInlining.lean Outdated
Comment thread Strata/Transform/FunctionInlining.lean Outdated
@tautschnig tautschnig self-assigned this Apr 22, 2026
Replaces the manual defs-list approach with Factory.callOfLFunc +
LFunc.computeTypeSubst + LExpr.applySubst, matching the inlining
path in LExprEval.eval. This enables:

- Polymorphic function inlining (type substitution via computeTypeSubst)
- Correct function lookup via the factory (same as the evaluator)
- Shared tryInlineCall helper used by both inlineFuncDefs and
  inlineRecFuncDefs

Also addresses Copilot review:
- substFvarsLifting for capture-safe substitution (Threads 4, 5)
- getLFuncCall replaced by callOfLFunc (Thread 1)
- Metadata preserved via factory (Thread 2)
- Tests added (Thread 3)
- Removed collectFuncDefs (no longer needed — factory has all defs)

Co-authored-by: Kiro <kiro-agent@users.noreply.github.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants