Skip to content

docs: Notes for IR annotations, inlining, and newtype erasure (#44)#129

Merged
Unisay merged 2 commits into
mainfrom
issue-44/notes-ir-inliner
Jun 25, 2026
Merged

docs: Notes for IR annotations, inlining, and newtype erasure (#44)#129
Unisay merged 2 commits into
mainfrom
issue-44/notes-ir-inliner

Conversation

@Unisay

@Unisay Unisay commented Jun 25, 2026

Copy link
Copy Markdown
Collaborator

Summary

Continues #44, the IR/inliner batch. Three more invariants get a GHC-style Note, each cited from its dependent sites. Comments only, so generated code, goldens, and eval oracles are unchanged.

  • Note [Inline annotations and inlining heuristics] in IR.Inliner. Traces an @inline pragma from a module comment through parseAnnotations, the annotation map, useAnnotation, and the expression ann, to Optimizer.isInlinableExpr reading it back with getAnn. Also notes the linker's synthesised Inline.Always on foreign-field wrappers. Cited from the optimizer and linker sites.

  • Note [Inliner annotations must all be consumed] in Backend.IR. The annotation map is a linear resource: filled by parseAnnotations, drained by useAnnotation, and checked empty by runRepM, which errors on leftovers. That check is what turns a typo'd or misplaced pragma into a reported error instead of a silent no-op.

  • Note [Newtype constructors are erased] in Backend.IR. One convention across three isNewtype sites: construction is identity (mkConstructor), application unwraps (mkApplication), and matching skips the constructor (mkBinder). Only the matching half was hinted at before.

A note on the De Bruijn item

The issue also lists "namespaced De Bruijn indices" and suggests folding it into the existing Note [Sequential scoping of Let bindings]. That Note already opens with the per-name index scheme, so rather than duplicate it I just pointed the Index newtype at it with a See Note.

Checklist

  • Added a changelog.d/ fragment for any user-facing change (scriv create
    in the dev shell), or this change ships nothing releasable (CI, docs, or an
    internal refactor).
  • In the dev shell (nix develop), fourmolu -i lib/ exe/ test/ and
    hlint lib/ exe/ test/ are clean.
  • In the dev shell, cabal test all passes; structural goldens were
    re-accepted on purpose if codegen moved (PSLUA_GOLDEN_ACCEPT=1), and
    eval/golden.txt still holds.

Add GHC-style Notes for three IR invariants and cite them from their
dependent sites. Comments only; generated code and goldens unchanged.

- Note [Inline annotations and inlining heuristics] (IR.Inliner): the pragma
  -> annotation map -> Ann -> optimizer-decision flow, plus the linker's
  synthesised Inline.Always on foreign wrappers.
- Note [Inliner annotations must all be consumed] (Backend.IR): the annotation
  map is linear; runRepM reports leftovers, which is how a typo'd pragma is
  caught.
- Note [Newtype constructors are erased] (Backend.IR): the three isNewtype
  sites (construction identity, application unwrap, matching skip).

The Ref Index type now points at the existing Note [Sequential scoping of Let
bindings], which already covers the per-name De Bruijn scheme.

Continues #44.

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Pull request overview

This PR continues the repo’s “GHC-style Note” documentation effort (#44) by adding and cross-referencing several Note [..] blocks that explain load-bearing IR invariants (inliner annotations as a linear resource, the end-to-end path of @inline pragmas into optimizer decisions, and newtype constructor erasure). The intent is to make these invariants easier to audit and keep consistent across producer/consumer sites without changing compiler behavior.

Changes:

  • Added Note [Inline annotations and inlining heuristics] (plus call-site See Note references) describing how @inline annotations flow from module comments into Ann and into inlining decisions.
  • Added Note [Inliner annotations must all be consumed] and referenced it from parseAnnotations/useAnnotation to document the “no leftovers” validation enforced by runRepM.
  • Added Note [Newtype constructors are erased] and referenced the three key isNewtype sites (construction/application/matching), plus a See Note pointer for Index.

Reviewed changes

Copilot reviewed 6 out of 6 changed files in this pull request and generated 1 comment.

Show a summary per file
File Description
lib/Language/PureScript/Backend/IR/Types.hs Adds a See Note pointer clarifying what Index selects.
lib/Language/PureScript/Backend/IR/Optimizer.hs Adds a See Note pointer from isInlinableExpr to the new inliner-annotation Note.
lib/Language/PureScript/Backend/IR/Linker.hs Adds a See Note pointer documenting the linker’s synthesized Inline.Always usage for foreign wrappers.
lib/Language/PureScript/Backend/IR/Inliner.hs Introduces Note [Inline annotations and inlining heuristics] describing the pragma→map→Ann→optimizer pipeline.
lib/Language/PureScript/Backend/IR.hs Introduces Notes documenting annotation consumption and newtype erasure, with See Note references at relevant sites.
changelog.d/20260625_201941_unisay_notes_ir_inliner.md Adds a changelog fragment describing the documentation additions.

Comment thread lib/Language/PureScript/Backend/IR/Inliner.hs Outdated
@Unisay Unisay marked this pull request as ready for review June 25, 2026 18:30
@Unisay Unisay merged commit 593704b into main Jun 25, 2026
2 checks passed
@Unisay Unisay deleted the issue-44/notes-ir-inliner branch June 25, 2026 18:30
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