Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Typed Macros #1251

Merged
merged 45 commits into from
Jun 27, 2022
Merged
Show file tree
Hide file tree
Changes from 43 commits
Commits
Show all changes
45 commits
Select commit Hold shift + click to select a range
16f30ff
fix: nesting of pattern info nodes
Kha Jun 24, 2022
c83ceb5
feat: always store quoted kind in antiquotation kind
Kha Mar 18, 2022
1cbd202
feat: introduce `TSyntax`
Kha Mar 19, 2022
901d053
chore: disable some anonymous antiquotations
Kha Apr 5, 2022
81fdd1d
refactor: make Init.Coe independent of Init.Notation
Kha Apr 5, 2022
b029a04
feat: early coercion from TSyntax to Syntax
Kha Apr 5, 2022
7bd3fc9
feat: allow anonymous antiquotations for `tacticSeq`
Kha Apr 5, 2022
4de8104
fix: store syntax kinds of parser aliases in order to construct corre…
Kha Jun 8, 2022
2a54f52
fix: `quote Name.anonymous`
Kha Apr 6, 2022
5932103
fix: avoid choice nodes with `LeadingIdentBehavior.both`
Kha Apr 6, 2022
178a6a1
fix: ignore `withPosition` when binding `macro` arguments
Kha Apr 8, 2022
9c64f79
fix: elaborating category quotations
Kha Apr 11, 2022
3143b75
fix: macro: inferred syntax kinds for literal parsers
Kha Apr 14, 2022
5795d7b
chore: introduce `doSeq` antiquotation
Kha Apr 15, 2022
41fc4bd
feat: upgrade TSyntax to union of kinds
Kha Apr 17, 2022
b3b0c56
chore: default `pp.rawOnError` to true for stage 0
Kha Apr 17, 2022
34fcd2e
fix: do not discriminate anonymous antiquots after all
Kha Apr 28, 2022
06f0ce3
chore: Nix: fix stage0-from-input
Kha Jun 9, 2022
0d6ee18
feat: `<|>` may produce a choice node of antiquotations
Kha Jun 14, 2022
22dd2c6
chore: prepare for next stage
Kha Apr 8, 2022
a9e6dae
chore: update stage0
Kha Jun 24, 2022
bb366e3
feat: more antiquotation kinds
Kha Jun 24, 2022
233669b
chore: work around `macro` limitations
Kha Jun 15, 2022
f83a98e
feat: more TSyntax API & coercions
Kha Jun 15, 2022
ffdf7ae
refactor: strengthen `Syntax` signatures
Kha Jun 15, 2022
5f415af
refactor: remove some unnecessary antiquotation kind annotations
Kha Jun 15, 2022
4efeef2
refactor: adapt raw syntax manipulations to TSyntax
Kha Jun 15, 2022
e71e4ac
fix: unclear TSyntax breakage
Kha Jun 15, 2022
869ecdf
chore: postpone TSyntax adoption for some parts
Kha Jun 15, 2022
ee98c91
chore: work around `for` type inference
Kha Jun 15, 2022
debb002
fix: incorrect antiquotation kind annotations
Kha Jun 15, 2022
013c815
chore: work around parameterized parser syntax kinds
Kha Jun 15, 2022
c2fab9d
chore: raw syntax kind accesses
Kha Jun 24, 2022
c7b935e
chore: fix tests
Kha Jun 24, 2022
0ca12bb
chore: work around "unknown free variable" bug
Kha Jun 24, 2022
08d4306
refactor: mkSimpleDelab
Kha Jun 24, 2022
596d0f2
refactor: make more use of quotations
Kha Jun 24, 2022
ddafed3
chore: changes to placate coercions
Kha Jun 24, 2022
6c5bd81
chore: remove unnecessary type annotations
Kha Jun 24, 2022
b62b933
feat: TSyntax singleton kind unexpanders
Kha Jun 24, 2022
9eff657
doc: TSyntax
Kha Jun 24, 2022
ede4507
chore: update Lake
Kha Jun 24, 2022
5b8d558
refactor: introduce common TSyntax abbreviations
Kha Jun 25, 2022
2f78111
chore: use Syntax.Level
Kha Jun 27, 2022
9762bb1
chore: add more comments
Kha Jun 27, 2022
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion doc/make/nix.md
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,7 @@ nix run .#HEAD-as-stage0.emacs-dev&
```
To run `nix build` on the second stage outside of the second editor, use
```bash
nix build .#stage0-from-input
nix build .#stage0-from-input --override-input lean-stage0 .\?rev=$(git rev-parse HEAD)
```
This setup will inadvertently change your `flake.lock` file, which you can revert when you are done.

Expand Down
4 changes: 3 additions & 1 deletion flake.nix
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,9 @@
};
tsandebug = tsan.override { debug = true; };
stage0-from-input = lean-packages.override {
stage0 = lean-stage0.packages.${system}.lean;
stage0 = pkgs.writeShellScriptBin "lean" ''
exec ${lean-stage0.packages.${system}.lean}/bin/lean -Dinterpreter.prefer_native=false "$@"
'';
};
inherit self;
};
Expand Down
12 changes: 6 additions & 6 deletions src/Init/Coe.lean
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ Released under Apache 2.0 license as described in the file LICENSE.
Authors: Leonardo de Moura
-/
prelude
import Init.Core
import Init.Prelude

universe u v w w'

Expand Down Expand Up @@ -40,7 +40,7 @@ class CoeFun (α : Sort u) (γ : outParam (α → Sort v)) where
class CoeSort (α : Sort u) (β : outParam (Sort v)) where
coe : α → β

syntax:max (name := coeNotation) "↑" term:max : term
syntax:1024 (name := coeNotation) "↑" term:1024 : term

instance coeTrans {α : Sort u} {β : Sort v} {δ : Sort w} [Coe β δ] [CoeTC α β] : CoeTC α δ where
coe a := Coe.coe (CoeTC.coe a : β)
Expand Down Expand Up @@ -81,18 +81,18 @@ instance coeSortToCoeTail [inst : CoeSort α β] : CoeTail α β where
/- Basic instances -/

@[inline] instance boolToProp : Coe Bool Prop where
coe b := b = true
coe b := Eq b true

instance boolToSort : CoeSort Bool Prop where
coe b := b = true
coe b := Eq b true

instance decPropToBool (p : Prop) [Decidable p] : CoeDep Prop p Bool where
coe := decide p

instance optionCoe {α : Type u} : CoeTail α (Option α) where
coe := some

instance subtypeCoe {α : Sort u} {p : α → Prop} : CoeHead { x // p x } α where
instance subtypeCoe {α : Sort u} {p : α → Prop} : CoeHead (Subtype p) α where
coe v := v.val

/- Coe bridge -/
Expand All @@ -105,7 +105,7 @@ instance subtypeCoe {α : Sort u} {p : α → Prop} : CoeHead { x // p x } α wh
-- Helper definition used by the elaborator. It is not meant to be used directly by users
@[inline] def Lean.Internal.coeM {m : Type u → Type v} {α β : Type u} [∀ a, CoeT α a β] [Monad m] (x : m α) : m β := do
let a ← x
pure <| CoeT.coe a
pure (CoeT.coe a)

instance [CoeFun α β] (a : α) : CoeDep α a (β a) where
coe := CoeFun.coe a
Expand Down
4 changes: 3 additions & 1 deletion src/Init/Conv.lean
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,9 @@ macro "erw " s:rwRuleSeq : conv => `(rw (config := { transparency := Meta.Transp
macro "args" : conv => `(congr)
macro "left" : conv => `(lhs)
macro "right" : conv => `(rhs)
macro "intro " xs:(colGt ident)* : conv => `(ext $xs*)
syntax "intro " (colGt ident)* : conv
macro_rules
| `(conv| intro $[$xs:ident]*) => `(conv| ext $xs*)

syntax enterArg := ident <|> group("@"? num)
syntax "enter " "[" (colGt enterArg),+ "]": conv
Expand Down
3 changes: 3 additions & 0 deletions src/Init/Data/Format/Syntax.lean
Original file line number Diff line number Diff line change
Expand Up @@ -44,4 +44,7 @@ def formatStx (stx : Syntax) (maxDepth : Option Nat := none) (showInfo := false)
instance : ToFormat (Syntax) := ⟨formatStx⟩
instance : ToString (Syntax) := ⟨@toString Format _ ∘ format⟩

instance : ToFormat (TSyntax k) := ⟨(format ·.raw)⟩
instance : ToString (TSyntax k) := ⟨(toString ·.raw)⟩

end Lean.Syntax
3 changes: 0 additions & 3 deletions src/Init/Data/Option/Basic.lean
Original file line number Diff line number Diff line change
Expand Up @@ -34,9 +34,6 @@ def toMonad [Monad m] [Alternative m] : Option α → m α
| none, _ => none
| some a, b => b a

@[inline] protected def map (f : α → β) (o : Option α) : Option β :=
Option.bind o (some ∘ f)

@[inline] protected def mapM [Monad m] (f : α → m β) (o : Option α) : m (Option β) := do
if let some a := o then
return some (← f a)
Expand Down
Loading