Skip to content

Conversation

@joehendrix
Copy link
Contributor

@joehendrix joehendrix commented Feb 12, 2026

Summary

  • Adds an app builtin constructor to the generated Init.Expr category in #strata_gen, alongside fvar and bvar
  • Fixes a bug where ofAst silently discarded arguments when bvar/fvar appeared as the head of an HNF-flattened application chain
  • The app constructor uses Expr α (not ArgF α) for both arguments — toAst wraps the arg with ArgF.expr, and ofAst folds HNF args back into Expr.app chains

Test plan

  • Round-trip tests for Expr.app in StrataTest/DDM/Integration/Lean/Gen.lean
  • Updated #guard_msgs for #print Expr in Gen.lean and DDMTranslate.lean
  • lake build passes
  • Investigate polymorphic function calls (type args on fvar)

🤖 Generated with Claude Code

@joehendrix
Copy link
Contributor Author

Polymorphic type arguments missing from parsed expression tree

When a polymorphic function like identity<a>(x : a) : a is called as identity(42), the type argument is completely absent from the generated concrete expression tree. The call parses as:

Expr.app (Expr.fvar 0) (Expr.natToInt 42)

but should include an explicit type application, e.g.:

Expr.app (Expr.app (Expr.fvar 0) (type int)) (Expr.natToInt 42)

This means ofAst's handling of ArgF.type on fvar/bvar heads (which currently throws) may need to be revisited.

Minimal repro

import Strata.Languages.Core.DDMTransform.Parse

namespace Strata.PolymorphicParsingBug

def pgm : Program :=
#strata
program Core;

function identity<a>(x : a) : a;

procedure Test() returns () {
  var x : int;
  x := identity(42);
};
#end

-- Show the raw concrete type for the procedure (commands[1])
#eval Strata.CoreDDM.Command.ofAst <| pgm.commands[1]!

end Strata.PolymorphicParsingBug

The #eval output shows Expr.app (Expr.fvar 0) (Expr.natToInt 42) with no type argument.

@joehendrix
Copy link
Contributor Author

Just to follow up on this. The representation is by design; polymorphic functions do not resolve their type arguments in the DDM currently.

Adds an `app` constructor to the generated `Init.Expr` category in
`#strata_gen`, alongside `fvar` and `bvar`. This fixes a bug where
`ofAst` silently discarded arguments when `bvar`/`fvar` appeared as
the head of an HNF-flattened application chain.

The `app` constructor uses `Expr α` (not `ArgF α`) for both arguments.
In the `toAst` direction, the arg is wrapped with `ArgF.expr`. In the
`ofAst` direction, HNF args are folded back into `Expr.app` chains
using `default` for intermediate annotations (since HNF discards them).

Documents that `bvar`/`fvar` arguments are always value-level and type
arguments are omitted from these expression nodes.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
@joehendrix joehendrix marked this pull request as ready for review February 12, 2026 18:19
@joehendrix joehendrix requested a review from a team as a code owner February 12, 2026 18:19
@joehendrix joehendrix changed the title WIP: Add app builtin constructor to generated Init.Expr category Add app builtin constructor to generated Init.Expr category Feb 12, 2026
@shigoel shigoel added this pull request to the merge queue Feb 12, 2026
Merged via the queue into main with commit 1564ce7 Feb 12, 2026
15 checks passed
@shigoel shigoel deleted the jhx/expr_app branch February 12, 2026 19:17
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.

3 participants