diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index cb2c04ec3..dc953e178 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -161,7 +161,7 @@ jobs: - name: Generate HTML (non-release) if: github.event_name != 'release' run: | - lake --quiet exe generate-manual --depth 2 --with-word-count "words.txt" --verbose --without-html-single + ./generate-html.sh --mode preview - name: Generate HTML (release) if: github.event_name == 'release' @@ -172,11 +172,16 @@ jobs: run: | scripts/check-examples-isolated.sh + - name: Verify tutorial project zip files build + if: github.event_name != 'release' + run: | + scripts/check-tutorial-zips.sh + - name: Generate proofreading HTML if: github.event_name == 'pull_request' id: generate run: | - lake --quiet exe generate-manual --depth 2 --verbose --draft --without-html-single --output "_out/draft" + ./generate-html.sh --mode preview --draft --output _out/draft-site - name: Report status to Lean PR if: always() && github.repository == 'leanprover/reference-manual' diff --git a/.github/workflows/overlay.yml b/.github/workflows/overlay.yml index b304c9ae9..d1edfb37c 100644 --- a/.github/workflows/overlay.yml +++ b/.github/workflows/overlay.yml @@ -1,5 +1,12 @@ name: Apply Overlays +# This workflow applies HTML overlays (canonical URLs, robots noindex, metadata.js) to +# deployed content and pushes to the postdeploy branches. +# +# In normal operation, the workflow_run trigger fires when release-tag.yml completes. +# Pushes made by release-tag.yml using GITHUB_TOKEN do NOT trigger the push events +# (GitHub prevents this to avoid infinite loops). + on: workflow_run: workflows: ["Deploy Tagged Version"] @@ -9,6 +16,7 @@ on: push: branches: - "deploy" + - "deploy-tutorials" workflow_dispatch: @@ -34,11 +42,12 @@ jobs: git config --global user.email "41898282+github-actions[bot]@users.noreply.github.com" git fetch origin deploy:deploy git fetch origin postdeploy:postdeploy - # TODO: Fetch tutorials branches when ready for production deployment: - # git fetch origin deploy-tutorials:deploy-tutorials - # git fetch origin postdeploy-tutorials:postdeploy-tutorials + git fetch origin deploy-tutorials:deploy-tutorials + git fetch origin postdeploy-tutorials:postdeploy-tutorials + # Run reference overlay if triggered by workflow_run, workflow_dispatch, or push to deploy - name: Run overlay script + if: github.event_name != 'push' || github.ref == 'refs/heads/deploy' run: | echo "Adding overlays to predeploy" # -B to prevent creation of __pycache__ directory @@ -46,15 +55,18 @@ jobs: python -B deploy/overlay.py . deploy postdeploy --site-dir reference - name: Push deploy branch + if: github.event_name != 'push' || github.ref == 'refs/heads/deploy' run: | git push origin postdeploy - # TODO: Add these steps when tutorials are ready for production deployment: - # - name: Run overlay script for tutorials - # run: | - # echo "Adding overlays to tutorials predeploy" - # python -B deploy/overlay.py . deploy-tutorials postdeploy-tutorials --site-dir tutorials - # - # - name: Push tutorials deploy branch - # run: | - # git push origin postdeploy-tutorials + # Run tutorials overlay if triggered by workflow_run, workflow_dispatch, or push to deploy-tutorials + - name: Run overlay script for tutorials + if: github.event_name != 'push' || github.ref == 'refs/heads/deploy-tutorials' + run: | + echo "Adding overlays to tutorials predeploy" + python -B deploy/overlay.py . deploy-tutorials postdeploy-tutorials --site-dir tutorials + + - name: Push tutorials deploy branch + if: github.event_name != 'push' || github.ref == 'refs/heads/deploy-tutorials' + run: | + git push origin postdeploy-tutorials diff --git a/.github/workflows/release-tag.yml b/.github/workflows/release-tag.yml index ad54bce36..2fd5f8666 100644 --- a/.github/workflows/release-tag.yml +++ b/.github/workflows/release-tag.yml @@ -115,7 +115,11 @@ jobs: - name: Detect deployment structure id: detect-structure run: | - # Check if we have the new combined site structure or old single-site structure + # Check if we have the new combined site structure or old single-site structure. + # The single-site structure is used for older builds that don't have tutorials. + # Because this workflow runs on tag push, it runs in the context of the tagged + # commit; after tutorial deployments are confirmed working, we can get rid of this + # conditional and just assume the new structure in this workflow. if [ -d "html/site/reference" ]; then STRUCTURE="new" REFERENCE_DIR="html/site/reference" @@ -134,11 +138,13 @@ jobs: echo "Making deployment from tag: '$TAG_NAME'" python deploy/release.py ${{ steps.detect-structure.outputs.reference_dir }} "$VERSION" deploy - # TODO: Add tutorials deployment when ready for production (requires new structure): - # python deploy/release.py html/site/tutorials "$VERSION" deploy-tutorials + if [ "${{ steps.detect-structure.outputs.structure }}" = "new" ]; then + python deploy/release.py html/site/tutorials "$VERSION" deploy-tutorials + fi - name: Push deploy branch run: | git push origin deploy - # TODO: Push tutorials branch when ready for production: - # git push origin deploy-tutorials + if [ "${{ steps.detect-structure.outputs.structure }}" = "new" ]; then + git push origin deploy-tutorials + fi diff --git a/.github/workflows/upload-snapshots.yml b/.github/workflows/upload-snapshots.yml index f3467832f..f8a423b96 100644 --- a/.github/workflows/upload-snapshots.yml +++ b/.github/workflows/upload-snapshots.yml @@ -42,31 +42,30 @@ jobs: # This is the site called 'lean-reference-manual-versions' NETLIFY_SITE_ID: "91dc33ef-6016-4ac7-bac1-d574e2254405" - # TODO: Add parallel job for tutorials when ready for production deployment: - # deploy-tutorials: - # name: Deploy tutorials release branch to hosting - # runs-on: ubuntu-latest - # if: - # ${{ github.event_name != 'workflow_run' || github.event.workflow_run.conclusion == - # 'success' }} - # steps: - # - name: Checkout postdeploy-tutorials branch - # uses: actions/checkout@v4 - # with: - # ref: "postdeploy-tutorials" - # - # - name: Upload the current state of the postdeploy-tutorials branch - # uses: nwtgck/actions-netlify@v2.0 - # with: - # publish-dir: "." - # production-branch: postdeploy-tutorials - # production-deploy: true - # github-token: ${{ secrets.GITHUB_TOKEN }} - # deploy-message: | - # Deploy tutorials from ${{ github.ref }} - # enable-commit-comment: false - # enable-pull-request-comment: false - # fails-without-credentials: true - # env: - # NETLIFY_AUTH_TOKEN: ${{ secrets.NETLIFY_AUTH_TOKEN }} - # NETLIFY_SITE_ID: "e76b4246-fee7-491e-91ef-a87fffff6ce1" + deploy-tutorials: + name: Deploy tutorials release branch to hosting + runs-on: ubuntu-latest + if: + ${{ github.event_name != 'workflow_run' || github.event.workflow_run.conclusion == + 'success' }} + steps: + - name: Checkout postdeploy-tutorials branch + uses: actions/checkout@v4 + with: + ref: "postdeploy-tutorials" + + - name: Upload the current state of the postdeploy-tutorials branch + uses: nwtgck/actions-netlify@v2.0 + with: + publish-dir: "." + production-branch: postdeploy-tutorials + production-deploy: true + github-token: ${{ secrets.GITHUB_TOKEN }} + deploy-message: | + Deploy tutorials from ${{ github.ref }} + enable-commit-comment: false + enable-pull-request-comment: false + fails-without-credentials: true + env: + NETLIFY_AUTH_TOKEN: ${{ secrets.NETLIFY_AUTH_TOKEN }} + NETLIFY_SITE_ID: "e76b4246-fee7-491e-91ef-a87fffff6ce1" diff --git a/.linkchecker/linkcheckerrc b/.linkchecker/linkcheckerrc index 0cd632270..0e8d40256 100644 --- a/.linkchecker/linkcheckerrc +++ b/.linkchecker/linkcheckerrc @@ -1,2 +1,6 @@ [filtering] ignorewarnings=url-content-too-large,url-too-long + +[checking] +# Moderate rate limit for localhost - higher values overwhelm Python's simple HTTP server +maxrequestspersecond=30 diff --git a/.linkchecker/server.py b/.linkchecker/server.py new file mode 100644 index 000000000..f50e8ae8b --- /dev/null +++ b/.linkchecker/server.py @@ -0,0 +1,23 @@ +#!/usr/bin/env python3 +""" +Simple HTTP server that adds a LinkChecker header to allow unlimited request rate. +""" +import http.server +import sys + +class LinkCheckerHTTPRequestHandler(http.server.SimpleHTTPRequestHandler): + def end_headers(self): + # Add LinkChecker header to allow maxrequestspersecond > 10 + self.send_header('LinkChecker', 'allowed') + super().end_headers() + +if __name__ == '__main__': + port = int(sys.argv[1]) if len(sys.argv) > 1 else 8877 + directory = sys.argv[2] if len(sys.argv) > 2 else '.' + + import os + os.chdir(directory) + + with http.server.HTTPServer(('', port), LinkCheckerHTTPRequestHandler) as httpd: + print(f"Serving at port {port} with LinkChecker header enabled") + httpd.serve_forever() diff --git a/Main.lean b/Main.lean index a2a8d6ade..4018f4097 100644 --- a/Main.lean +++ b/Main.lean @@ -1,5 +1,5 @@ /- -Copyright (c) 2024 Lean FRO LLC. All rights reserved. +Copyright (c) 2024-2025 Lean FRO LLC. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Author: David Thrane Christiansen -/ @@ -44,7 +44,7 @@ where extraFiles := [("static", "static")], extraHead := #[plausible, staticJs, staticCss], emitTeX := false, - emitHtmlSingle := true, -- for proofreading + emitHtmlSingle := .no, logo := some "/static/lean_logo.svg", sourceLink := some "https://github.com/leanprover/reference-manual", issueLink := some "https://github.com/leanprover/reference-manual/issues", diff --git a/Manual.lean b/Manual.lean index c11321c2f..894fd2ad9 100644 --- a/Manual.lean +++ b/Manual.lean @@ -18,7 +18,6 @@ import Manual.ErrorExplanations import Manual.Tactics import Manual.Simp import Manual.Grind -import Manual.VCGen import Manual.BasicTypes import Manual.Iterators import Manual.BasicProps @@ -31,6 +30,7 @@ import Manual.Releases import Manual.Namespaces import Manual.Runtime import Manual.SupportedPlatforms +import Manual.VCGen open Verso.Genre Manual open Verso.Genre.Manual.InlineLean @@ -58,7 +58,7 @@ Along with many other parts of Lean, the tactic language is user-extensible, so Tactics are written in Lean itself, and can be used immediately upon definition; rebuilding the prover or loading external modules is not required. Lean is also a pure *functional programming language*, with features such as a run-time system based on reference counting that can efficiently work with packed array structures, multi-threading, and monadic {name}`IO`. -As befits a programming language, Lean is primarily implemented in itself, including the language server, build tool, {tech}[elaborator], and tactic system. +As befits a programming language, Lean is primarily implemented in itself, including the language server, build tool, {tech (key := "Lean elaborator") -normalize}[elaborator], and tactic system. This very book is written in [Verso](https://github.com/leanprover/verso), a documentation authoring tool written in Lean. Familiarity with Lean's programming features is valuable even for users whose primary interest is in writing proofs, because Lean programs are used to implement new tactics and proof automation. diff --git a/Manual/BuildTools/Lake/CLI.lean b/Manual/BuildTools/Lake/CLI.lean index d29cbef3a..9b1828114 100644 --- a/Manual/BuildTools/Lake/CLI.lean +++ b/Manual/BuildTools/Lake/CLI.lean @@ -308,7 +308,7 @@ Single-character flags cannot be combined; `-HR` is not equivalent to `-H -R`. : {lakeOptDef flag}`--reconfigure` or {lakeOptDef flag}`-R` - Normally, the {tech}[package configuration] file is {tech (key := "elaborator")}[elaborated] when a package is first configured, with the result cached to a {tech}[`.olean` file] that is used for future invocations until the package configuration + Normally, the {tech}[package configuration] file is {tech (key := "elaborator") -normalize}[elaborated] when a package is first configured, with the result cached to a {tech}[`.olean` file] that is used for future invocations until the package configuration Providing this flag causes the configuration file to be re-elaborated. : {lakeOptDef flag}`--keep-toolchain` diff --git a/Manual/Defs.lean b/Manual/Defs.lean index 4d128cc76..7027b4030 100644 --- a/Manual/Defs.lean +++ b/Manual/Defs.lean @@ -30,7 +30,7 @@ The following commands in Lean are definition-like: {TODO}[Render commands as th * {keyword}`theorem` * {keyword}`opaque` -All of these commands cause Lean to {tech (key := "elaborator")}[elaborate] a term based on a {tech}[signature]. +All of these commands cause Lean to {tech (key := "elaborator") -normalize}[elaborate] a term based on a {tech}[signature]. With the exception of {keywordOf Lean.Parser.Command.example}`example`, which discards the result, the resulting expression in Lean's core language is saved for future use in the environment. The {keywordOf Lean.Parser.Command.declaration}`instance` command is described in the {ref "instance-declarations"}[section on instance declarations]. diff --git a/Manual/Elaboration.lean b/Manual/Elaboration.lean index 24d41dc3a..2e7f9e816 100644 --- a/Manual/Elaboration.lean +++ b/Manual/Elaboration.lean @@ -39,7 +39,7 @@ Roughly speaking, Lean's processing of a source file can be divided into the fol : Elaboration - {deftech (key := "elaborator")}[Elaboration] is the process of transforming Lean's user-facing syntax into its core type theory. + {deftech (key := "Lean elaborator") -normalize}[Elaboration] is the process of transforming Lean's user-facing syntax into its core type theory. This core theory is much simpler, enabling the trusted kernel to be very small. Elaboration additionally produces metadata, such as proof states or the types of expressions, used for Lean's interactive features, storing them in a side table. @@ -105,7 +105,7 @@ tag := "macro-and-elab" %%% Having parsed a command, the next step is to elaborate it. -The precise meaning of {deftech}_elaboration_ depends on what is being elaborated: elaborating a command effects a change in the state of Lean, while elaborating a term results in a term in Lean's core type theory. +The precise meaning of {deftech -normalize}_elaboration_ depends on what is being elaborated: elaborating a command effects a change in the state of Lean, while elaborating a term results in a term in Lean's core type theory. Elaboration of both commands and terms may be recursive, both because of command combinators such as {keywordOf Lean.Parser.Command.in}`in` and because terms may contain other terms. Command and term elaboration have different capabilities. @@ -293,7 +293,7 @@ The compiler stores an intermediate representation in an environment extension. For straightforwardly structurally recursive functions, the translation will use the type's recursor. These functions tend to be relatively efficient when run in the kernel, their defining equations hold definitionally, and they are easy to understand. -Functions that use other patterns of recursion that cannot be captured by the type's recursor are translated using {deftech}[well-founded recursion], which is structural recursion on a proof that some {deftech}_measure_ decreases at each recursive call, or using {ref "partial-fixpoint"}[partial fixpoints], which logically capture at least part of a function's specification by appealing to domain-theoretic constructions. +Functions that use other patterns of recursion that cannot be captured by the type's recursor are translated using {tech}[well-founded recursion], which is structural recursion on a proof that some {tech}[measure] decreases at each recursive call, or using {ref "partial-fixpoint"}[partial fixpoints], which logically capture at least part of a function's specification by appealing to domain-theoretic constructions. Lean can automatically derive many of these termination proofs, but some require manual proofs. Well-founded recursion is more flexible, but the resulting functions are often slower to execute in the kernel due to the proof terms that show that a measure decreases, and their defining equations may hold only propositionally. To provide a uniform interface to functions defined via structural and well-founded recursion and to check its own correctness, the elaborator proves {deftech}[equational lemmas] that relate the function to its original definition. diff --git a/Manual/Grind/EMatching.lean b/Manual/Grind/EMatching.lean index a1840315e..d6bb3c1dd 100644 --- a/Manual/Grind/EMatching.lean +++ b/Manual/Grind/EMatching.lean @@ -32,7 +32,7 @@ Each fact added to the whiteboard by E-matching is referred to as an {deftech (k Annotating theorems for E-matching, thus adding them to the index, is essential for enabling {tactic}`grind` to make effective use of a library. In addition to user-specified theorems, {tactic}`grind` uses automatically generated equations for {keywordOf Lean.Parser.Term.match}`match`-expressions as E-matching theorems. -Behind the scenes, the {tech}[elaborator] generates auxiliary functions that implement pattern matches, along with equational theorems that specify their behavior. +Behind the scenes, the {tech (key := "Lean elaborator")}[elaborator] generates auxiliary functions that implement pattern matches, along with equational theorems that specify their behavior. Using these equations with E-matching enables {tactic}`grind` to reduce these instances of pattern matching. diff --git a/Manual/Grind/ExtendedExamples.lean b/Manual/Grind/ExtendedExamples.lean index 7ac200443..bc880375c 100644 --- a/Manual/Grind/ExtendedExamples.lean +++ b/Manual/Grind/ExtendedExamples.lean @@ -12,7 +12,6 @@ import Manual.Meta import Manual.Grind.ExtendedExamples.Integration import Manual.Grind.ExtendedExamples.IfElseNorm -import Manual.Grind.ExtendedExamples.IndexMap open Verso.Genre Manual open Verso.Genre.Manual.InlineLean @@ -27,8 +26,10 @@ open Lean.Grind tag := "grind-bigger-examples" %%% +:::TODO +Properly link to tutorial section +::: + {include 1 Manual.Grind.ExtendedExamples.Integration} {include 1 Manual.Grind.ExtendedExamples.IfElseNorm} - -{include 1 Manual.Grind.ExtendedExamples.IndexMap} diff --git a/Manual/IO/Threads.lean b/Manual/IO/Threads.lean index 1de2a7115..01f76a140 100644 --- a/Manual/IO/Threads.lean +++ b/Manual/IO/Threads.lean @@ -30,7 +30,7 @@ variable {α : Type u} ``` {deftech}_Tasks_ are the fundamental primitive for writing multi-threaded code. -A {lean}`Task α` represents a computation that, at some point, will {deftech}_resolve_ to a value of type `α`; it may be computed on a separate thread. +A {lean}`Task α` represents a computation that, at some point, will {tech (key := "resolve promise")}_resolve_ to a value of type `α`; it may be computed on a separate thread. When a task has resolved, its value can be read; attempting to get the value of a task before it resolves causes the current thread to block until the task has resolved. Tasks are similar to promises in JavaScript, `JoinHandle` in Rust, and `Future` in Scala. @@ -52,7 +52,7 @@ Tasks may be explicitly cancelled using {name}`IO.cancel`. The Lean runtime maintains a thread pool for running tasks. The size of the thread pool is determined by the environment variable {envVar +def}`LEAN_NUM_THREADS` if it is set, or by the number of logical processors on the current machine otherwise. The size of the thread pool is not a hard limit; in certain situations it may be exceeded to avoid deadlocks. -By default, these threads are used to run tasks; each task has a {deftech}_priority_ ({name}`Task.Priority`), and higher-priority tasks take precedence over lower-priority tasks. +By default, these threads are used to run tasks; each task has a {deftech (key := "task priority")}_priority_ ({name}`Task.Priority`), and higher-priority tasks take precedence over lower-priority tasks. Tasks may also be assigned to dedicated threads by spawning them with a sufficiently high priority. {docstring Task (label := "type") +hideStructureConstructor +hideFields} @@ -162,7 +162,7 @@ Pure tasks are terminated automatically upon cancellation. # Promises Promises represent a value that will be supplied in the future. -Supplying the value is called {deftech (key := "resolve")}_resolving_ the promise. +Supplying the value is called {deftech (key := "resolve promise")}_resolving_ the promise. Once created, a promise can be stored in a data structure or passed around like any other value, and attempts to read from it will block until it is resolved. diff --git a/Manual/Interaction.lean b/Manual/Interaction.lean index 6e7a6df0d..5ec270049 100644 --- a/Manual/Interaction.lean +++ b/Manual/Interaction.lean @@ -28,7 +28,7 @@ Lean's interactive features are based on a different paradigm. Rather than a separate command prompt outside of the program, Lean provides {tech}[commands] for accomplishing the same tasks in the context of a source file. By convention, commands that are intended for interactive use rather than as part of a durable code artifact are prefixed with {keyword}`#`. -Information from Lean commands is available in the {deftech}_message log_, which accumulates output from the {tech}[elaborator]. +Information from Lean commands is available in the {deftech}_message log_, which accumulates output from the {tech (key := "Lean elaborator")}[elaborator]. Each entry in the message log is associated with a specific source range and has a {deftech}_severity_. There are three severities: {lean (type := "Lean.MessageSeverity")}`information` is used for messages that do not indicate a problem, {lean (type := "Lean.MessageSeverity")}`warning` indicates a potential problem, and {lean (type := "Lean.MessageSeverity")}`error` indicates a definite problem. For interactive commands, results are typically returned as informational messages that are associated with the command's leading keyword. @@ -56,7 +56,7 @@ Use {keywordOf Lean.reduceCmd}`#reduce` to instead reduce terms using the reduct ::: -{keywordOf Lean.Parser.Command.eval}`#eval` always {tech (key := "elaborator")}[elaborates] and compiles the provided term. +{keywordOf Lean.Parser.Command.eval}`#eval` always {tech (key := "Lean elaborator")}[elaborates] and compiles the provided term. It then checks whether the term transitively depends on any uses of {lean}`sorry`, in which case evaluation is terminated unless the command was invoked as {keywordOf Lean.Parser.Command.eval}`#eval!`. This is because compiled code may rely on compile-time invariants (such as array lookups being in-bounds) that are ensured by proofs of suitable statements, and running code that contains incomplete proofs (or uses of {lean}`sorry` that “prove” incorrect statements) can cause Lean itself to crash. diff --git a/Manual/Language/Namespaces.lean b/Manual/Language/Namespaces.lean index 1831c8e0f..ddc50f86e 100644 --- a/Manual/Language/Namespaces.lean +++ b/Manual/Language/Namespaces.lean @@ -65,7 +65,7 @@ end Forest # Namespaces and Section Scopes -Every {tech}[section scope] has a {deftech}_current namespace_, which is determined by the {keywordOf Lean.Parser.Command.namespace}`namespace` command.{margin}[The {keywordOf Lean.Parser.Command.namespace}`namespace` command is described in the {ref "scope-commands"}[section on commands that introduce section scopes].] +Every {tech}[section scope] has a {tech}[current namespace], which is determined by the {keywordOf Lean.Parser.Command.namespace}`namespace` command.{margin}[The {keywordOf Lean.Parser.Command.namespace}`namespace` command is described in the {ref "scope-commands"}[section on commands that introduce section scopes].] Names that are declared within the section scope are added to the current namespace. If the declared name has more than one component, then its namespace is nested within the current namespace; the body of the declaration's current namespace is the nested namespace. Section scopes also include a set of {deftech}_opened namespaces_, which are namespaces whose contents are in scope without additional qualification. diff --git a/Manual/Meta.lean b/Manual/Meta.lean index 48067ce20..8be89346c 100644 --- a/Manual/Meta.lean +++ b/Manual/Meta.lean @@ -35,7 +35,6 @@ import Manual.Meta.Syntax import Manual.Meta.Tactics import Manual.Meta.SpliceContents import Manual.Meta.Markdown -import Manual.Meta.Imports import Manual.Meta.Namespace @@ -392,6 +391,15 @@ def ffi.descr : BlockDescr where toTeX := some <| fun _goI goB _ _ contents => contents.mapM goB -- TODO +open Verso.Output.Html in +inline_extension Inline.multiCode where + traverse _ _ _ := pure none + toHtml := some <| fun goI _id _data contents => do return {{{{← contents.mapM goI}}}} + toTeX := none + +@[role] +def multiCode : RoleExpanderOf Unit + | (), contents => do ``(Inline.other Inline.multiCode #[$(← contents.mapM elabInline),*]) structure LeanSectionConfig where diff --git a/Manual/Meta/Example.lean b/Manual/Meta/Example.lean index 78be9402d..7c5d34644 100644 --- a/Manual/Meta/Example.lean +++ b/Manual/Meta/Example.lean @@ -6,7 +6,6 @@ Author: David Thrane Christiansen import VersoManual import Manual.Meta.Figure -import Manual.Meta.Imports import Manual.Meta.LzCompress import Lean.Elab.InfoTree.Types diff --git a/Manual/Meta/Imports.lean b/Manual/Meta/Imports.lean deleted file mode 100644 index 03fe356ec..000000000 --- a/Manual/Meta/Imports.lean +++ /dev/null @@ -1,54 +0,0 @@ -/- -Copyright (c) 2025 Lean FRO LLC. All rights reserved. -Released under Apache 2.0 license as described in the file LICENSE. -Author: David Thrane Christiansen --/ - -import VersoManual -import Lean.Elab.InfoTree.Types -import SubVerso.Highlighting.Code -import Manual.Meta.Basic - -open scoped Lean.Doc.Syntax - -open Verso Doc Elab -open Lean Elab -open Verso.Genre.Manual InlineLean Scopes -open Verso.SyntaxUtils -open SubVerso.Highlighting -open ArgParse - -namespace Manual - -structure ImportsParams where - «show» : Bool := true - -instance : FromArgs ImportsParams m where - fromArgs := ImportsParams.mk <$> .flag `show true (some "Whether to show the import header") - -@[code_block] -def imports : CodeBlockExpanderOf ImportsParams - | { «show» }, str => do - let altStr ← parserInputString str - let p := Parser.whitespace >> Parser.Module.header.fn - let headerStx ← p.parseString altStr - let hl ← highlight headerStx #[] {} - if «show» then - ``(Block.other (Block.lean $(quote hl) {}) #[Block.code $(quote str.getString)]) - else - ``(Block.empty) - -@[role] -def «import» : RoleExpanderOf Unit - | (), contents => do - let some str ← oneCodeStr? contents - | ``(Verso.Doc.Inline.empty) - - let p := Lean.Parser.Module.import.fn - let stx ← withoutModifyingEnv do - modifyEnv fun env => - Parser.parserExtension.modifyState env fun st => - { st with tokens := Parser.Module.updateTokens st.tokens } - Lean.Doc.parseStrLit p str - let hl ← highlight stx #[] {} - ``(Inline.other (Inline.lean $(quote hl) {}) #[Inline.code $(quote str.getString)]) diff --git a/Manual/Meta/ParserAlias.lean b/Manual/Meta/ParserAlias.lean index 882558c69..bcc4ee9b2 100644 --- a/Manual/Meta/ParserAlias.lean +++ b/Manual/Meta/ParserAlias.lean @@ -69,7 +69,7 @@ def parserAlias : DirectiveExpander pure #[← ``(Verso.Doc.Block.other (Block.parserAlias $(quote opts.name) $(quote declName) $(quote opts.show) $(quote stackSz?) $(quote autoGroupArgs) $(quote docs?) $(quote argCount)) #[$(contents ++ userContents),*])] @[inline] -private def getFromJson {α} [Inhabited α] [FromJson α] (v : Json) : HtmlT Genre.Manual (ReaderT ExtensionImpls IO) α:= +private def getFromJson {α} [Monad m] [Inhabited α] [FromJson α] (v : Json) : HtmlT Genre.Manual m α:= match FromJson.fromJson? (α := α) v with | .error e => do Verso.Doc.Html.HtmlT.logError diff --git a/Manual/Meta/Syntax.lean b/Manual/Meta/Syntax.lean index 994adbf7c..9c8939ec7 100644 --- a/Manual/Meta/Syntax.lean +++ b/Manual/Meta/Syntax.lean @@ -830,7 +830,7 @@ where return bar ++ .nest 2 (← production which stx |>.run' {}) def testGetBnf (config : FreeSyntaxConfig) (isFirst : Bool) (stxs : List Syntax) : TermElabM String := do - let (tagged, _) ← getBnf config isFirst stxs |>.run (← moduleGenreElabContext) {} {partContext := ⟨⟨default, default, default, default, default⟩, default⟩} + let (tagged, _) ← getBnf config isFirst stxs |>.run ⟨← ``(Manual), mkConst ``Manual, .always, none⟩ {} {partContext := ⟨⟨default, default, default, default, default⟩, default⟩} pure tagged.stripTags namespace Tests @@ -1352,7 +1352,7 @@ window.addEventListener("load", () => { "# open Verso.Output Html HtmlT in -private def nonTermHtmlOf (kind : Name) (doc? : Option String) (rendered : Html) : HtmlT Manual (ReaderT ExtensionImpls IO) Html := do +private def nonTermHtmlOf (kind : Name) (doc? : Option String) (rendered : Html) : HtmlT Manual (ReaderT Multi.AllRemotes (ReaderT ExtensionImpls IO)) Html := do let xref ← match (← state).resolveDomainObject syntaxKindDomain kind.toString with | .error _ => pure none @@ -1398,7 +1398,7 @@ def noLook (ctx : GrammarHtmlContext) : GrammarHtmlContext := end GrammarHtmlContext open Verso.Output Html in -abbrev GrammarHtmlM := ReaderT GrammarHtmlContext (HtmlT Manual (ReaderT ExtensionImpls IO)) +abbrev GrammarHtmlM := ReaderT GrammarHtmlContext (HtmlT Manual (ReaderT Multi.AllRemotes (ReaderT ExtensionImpls IO))) private def lookingAt (k : Name) : GrammarHtmlM α → GrammarHtmlM α := withReader (·.look k) @@ -1492,7 +1492,7 @@ where let inner ← go if let some k := (← read).lookingAt then unless k == nullKind do - if let some tgt := ((← HtmlT.state (genre := Manual) (m := ReaderT ExtensionImpls IO)).localTargets.keyword k none)[0]? then + if let some tgt := ((← HtmlT.state (genre := Manual) (m := ReaderT Multi.AllRemotes (ReaderT ExtensionImpls IO))).localTargets.keyword k none)[0]? then return {{{{inner}}}} return {{{{inner}}}} | .nonterminal k doc? => do diff --git a/Manual/NotationsMacros.lean b/Manual/NotationsMacros.lean index 0231ffb93..28ccd2455 100644 --- a/Manual/NotationsMacros.lean +++ b/Manual/NotationsMacros.lean @@ -62,7 +62,7 @@ They can be combined flexibly to achieve the necessary results: tag := "macros" %%% -{deftech}_Macros_ are transformations from {name Lean.Syntax}`Syntax` to {name Lean.Syntax}`Syntax` that occur during {tech (key := "elaborator")}[elaboration] and during {ref "tactic-macros"}[tactic execution]. +{deftech}_Macros_ are transformations from {name Lean.Syntax}`Syntax` to {name Lean.Syntax}`Syntax` that occur during {tech (key := "elaborator") -normalize}[elaboration] and during {ref "tactic-macros"}[tactic execution]. Replacing syntax with the result of transforming it with a macro is called {deftech}_macro expansion_. Multiple macros may be associated with a single {tech}[syntax kind], and they are attempted in order of definition. Macros are run in a {tech}[monad] that has access to some compile-time metadata and has the ability to either emit an error message or to delegate to subsequent macros, but the macro monad is much less powerful than the elaboration monads. diff --git a/Manual/NotationsMacros/SyntaxDef.lean b/Manual/NotationsMacros/SyntaxDef.lean index db1ab2e24..bda993def 100644 --- a/Manual/NotationsMacros/SyntaxDef.lean +++ b/Manual/NotationsMacros/SyntaxDef.lean @@ -718,7 +718,7 @@ A variant of list literals that requires double square brackets and allows a tra syntax "[[" term,*,? "]]" : term ``` -Adding a {deftech}[macro] that describes how to translate it into an ordinary list literal allows it to be used in tests. +Adding a {tech}[macro] that describes how to translate it into an ordinary list literal allows it to be used in tests. ```lean macro_rules | `(term|[[$e:term,*]]) => `([$e,*]) diff --git a/Manual/SourceFiles.lean b/Manual/SourceFiles.lean index f1fe6fc35..c83753149 100644 --- a/Manual/SourceFiles.lean +++ b/Manual/SourceFiles.lean @@ -17,7 +17,7 @@ tag := "files" htmlSplit := .never %%% -The smallest unit of compilation in Lean is a single {deftech}[source file]. +The smallest unit of compilation in Lean is a single {tech}[source file]. Source files may import other source files based on their file names. In other words, the names and folder structures of files are significant in Lean code. @@ -642,7 +642,7 @@ tag := "meta-phase" Definitions in Lean result in both a representation in the type theory that is designed for formal reasoning and a compiled representation that is designed for execution. This compiled representation is used to generate machine code, but it can also be executed directly using an interpreter. -The code runs during {tech}[elaboration], such as {ref "tactics"}[tactics] or {ref "macros"}[macros], is the compiled form of definitions. +The code runs during {tech -normalize}[elaboration], such as {ref "tactics"}[tactics] or {ref "macros"}[macros], is the compiled form of definitions. If this compiled representation changes, then any code created by it may no longer be up to date, and it must be re-run. Because the compiler performs non-trivial optimizations, changes to any definition in the transitive dependency chain of a function could in principle invalidate its compiled representation. This means that metaprograms exported by modules induce a much stronger coupling than ordinary definitions. @@ -856,7 +856,7 @@ tag := "code-distribution" %%% -Lean modules are organized into {deftech}_packages_, which are units of code distribution. +Lean modules are organized into {tech}_packages_, which are units of code distribution. A {tech}[package] may contain multiple libraries or executables. Code in a package that is intended for use by other Lean packages is organized into {deftech (key:="library")}[libraries]. diff --git a/Manual/Terms.lean b/Manual/Terms.lean index 090545f91..fb9e7ff59 100644 --- a/Manual/Terms.lean +++ b/Manual/Terms.lean @@ -28,7 +28,7 @@ tag := "terms" {deftech}_Terms_ are the principal means of writing mathematics and programs in Lean. -The {tech}[elaborator] translates them to Lean's minimal core language, which is then checked by the kernel and compiled for execution. +The {deftech (key := "Lean elaborator")}[elaborator] translates them to Lean's minimal core language, which is then checked by the kernel and compiled for execution. The syntax of terms is {ref "syntax-ext"}[arbitrarily extensible]; this chapter documents the term syntax that Lean provides out-of-the-box. # Identifiers @@ -410,7 +410,7 @@ Implicit parameters come in three varieties: : Instance implicit parameters - Arguments for {deftech}_instance implicit_ parameters are found via {ref "instance-synth"}[type class synthesis]. + Arguments for {tech}_instance implicit_ parameters are found via {ref "instance-synth"}[type class synthesis]. Instance implicit parameters are written in square brackets (`[` and `]`). Unlike the other kinds of implicit parameter, instance implicit parameters that are written without a `:` specify the parameter's type rather than providing a name. Furthermore, only a single name is allowed. diff --git a/Manual/Types.lean b/Manual/Types.lean index 1c1b49ccb..6939b5f99 100644 --- a/Manual/Types.lean +++ b/Manual/Types.lean @@ -24,7 +24,7 @@ shortContextTitle := "Type System" %%% {deftech}_Terms_, also known as {deftech}_expressions_, are the fundamental units of meaning in Lean's core language. -They are produced from user-written syntax by the {tech}[elaborator]. +They are produced from user-written syntax by the {tech (key := "Lean elaborator")}[elaborator]. Lean's type system relates terms to their _types_, which are also themselves terms. Types can be thought of as denoting sets, while terms denote individual elements of these sets. A term is {deftech}_well-typed_ if it has a type under the rules of Lean's type theory. diff --git a/Manual/VCGen.lean b/Manual/VCGen.lean index a0989bb7a..0a0e8051c 100644 --- a/Manual/VCGen.lean +++ b/Manual/VCGen.lean @@ -8,7 +8,6 @@ import VersoManual import Manual.Meta import Manual.Papers -import Manual.VCGen.Tutorial import Std.Tactic.Do @@ -37,8 +36,8 @@ tag := "mvcgen-tactic" %%% The {tactic}`mvcgen` tactic implements a _monadic verification condition generator_: -It breaks down a goal involving a program written using Lean's imperative {keywordOf Lean.Parser.Term.do}`do` notation into a number of smaller {deftech}_verification conditions_ ({deftech}[VCs]) that are sufficient to prove the goal. -In addition to a reference that describes the use of {tactic}`mvcgen`, this chapter includes a {ref "mvcgen-tactic-tutorial"}[tutorial] that can be read independently of the reference. +It breaks down a goal involving a program written using Lean's imperative {keywordOf Lean.Parser.Term.do}`do` notation into a number of smaller {tech}_verification conditions_ ({deftech}[VCs]) that are sufficient to prove the goal. +In addition to a reference that describes the use of {tactic}`mvcgen`, this chapter includes a {ref "mvcgen-tactic-tutorial" (remote := "tutorials")}[tutorial] that can be read independently of the reference. In order to use the {tactic}`mvcgen` tactic, {module}`Std.Tactic.Do` must be imported and the namespace {namespace}`Std.Do` must be opened. @@ -933,5 +932,3 @@ theorem bump_correct' : simp_all [bump] ``` ::: - -{include 0 Manual.VCGen.Tutorial} diff --git a/README.md b/README.md index fbb5e08ed..472c5ab9b 100644 --- a/README.md +++ b/README.md @@ -110,15 +110,15 @@ Please see [CONTRIBUTING.md](CONTRIBUTING.md) for more information. TL;DR: push a tag of the form `vX.Y.Z` onto the commit that should be released as the manual for that version, and the rest is automatic. -This directory contains the deployment infrastructure for the -reference manual. Deployment happens in GitHub Actions, in response to -certain tags being pushed. Because the latest version of the GH action -file will always be used, and we want to be able to mutate tags to -re-deploy old manual versions (e.g. to update CSS for consistent look -and feel while keeping content version-accurate, or add a "THIS IS -OBSOLETE" banner in a few years). Thus, the steps of the workflow that -might change are captured in scripts that are versioned along with the -code. +This repository contains the deployment infrastructure for both the +reference manual and the tutorials site. Deployment happens in GitHub +Actions, in response to certain tags being pushed. Because the latest +version of the GH action file will always be used, and we want to be +able to mutate tags to re-deploy old manual versions (e.g. to update +CSS for consistent look and feel while keeping content +version-accurate, or add a "THIS IS OBSOLETE" banner in a few years), +the steps of the workflow that might change are captured in scripts +that are versioned along with the code. The files are: @@ -128,19 +128,22 @@ The files are: - `build.sh` is used to build the executable that generates the manual. -- `generate.sh` actually generates release-ready HTML, saving it in - `/html` in the root of this repository. +- `generate.sh` builds both the reference manual and tutorials, saving + them in `/html/site/reference` and `/html/site/tutorials`. - `release.py` puts the generated HTML in the right place on a new - commit on the branch `deploy` + commit on a deployment branch (`deploy` for the reference manual, + `deploy-tutorials` for tutorials). Everything above is what needs to happen specifically to the single version of the documentation that is being updated in the course of the deploy. There is one further step, which is computing the desired -state of the final `postdeploy` branch from the state in the branch -`deploy`. This is done by the script `overlay.py`, which is triggered -by pushes to `deploy`, and therefore runs at branch `main` rather than -at the tag being pushed. +state of the final `postdeploy` branches from the state in the +`deploy` branches. This is done by the script `overlay.py`, which is +triggered by pushes to `deploy`, and therefore runs at branch `main` +rather than at the tag being pushed. It processes both the reference +manual (`deploy` → `postdeploy`) and tutorials (`deploy-tutorials` → +`postdeploy-tutorials`). We might have named the two branches `predeploy` and `deploy`, but chose instead `deploy` and `postdeploy` so that we cold leave @@ -149,24 +152,40 @@ still have workflows that emit commits to `deploy`. ## Deployment Overview -The goal is to have versioned snapshots of the manual, with a -structure like: +The goal is to have versioned snapshots of both the reference manual +and tutorials, with a structure like: -- `https://lean-lang.org/doc/reference/latest/`- latest version -- `https://lean-lang.org/doc/reference/4.19.0/` - manual for v4.19.0 -- `https://lean-lang.org/doc/reference/4.20.0/` - manual for v4.19.0 - -and so forth. `https://lean-lang.org/doc/reference/` should redirect -to `latest`. It's important to be able to edit past deployments as -well. - -An orphan branch, called `deploy`, should at all times contain this -structure. With the three URLs above, the branch would contain three -directories: - -- `/4.20.0/` - built HTML served for 4.20.0 -- `/4.19.0/` - built HTML served for 4.19.0 -- `/latest` - symlink to `/4.20.0` +- `https://lean-lang.org/doc/reference/latest/` - latest version +- `https://lean-lang.org/doc/reference/stable/` - latest stable + version +- `https://lean-lang.org/doc/reference/4.19.0/` - reference for + v4.19.0 +- `https://lean-lang.org/doc/reference/4.20.0/` - reference for + v4.20.0 +- `https://lean-lang.org/doc/tutorials/latest/` - latest tutorials +- `https://lean-lang.org/doc/tutorials/stable/` - latest stable + tutorials +- `https://lean-lang.org/doc/tutorials/4.19.0/` - tutorials for + v4.19.0 +- `https://lean-lang.org/doc/tutorials/4.20.0/` - tutorials for + v4.20.0 + +and so forth. The base URLs should redirect to `latest`. It's +important to be able to edit past deployments as well. + +Orphan branches `deploy` and `deploy-tutorials` contain the versioned +content for each site. For example, the `deploy` branch might contain: + +- `/4.25.0-rc1/` - built HTML for 4.25.0-rc1 +- `/4.24.0/` - built HTML for 4.24.0 +- `/4.23.0/` - built HTML for 4.23.0 +- `/latest/` - copy of `/4.25.0-rc1/` (the most recent version) +- `/stable/` - copy of `/4.24.0/` (the most recent non-RC version) + +The `latest` and `stable` directories are full copies rather than +symlinks because Netlify deployment doesn't support symlinks. + +The `deploy-tutorials` branch has the same structure for tutorials. The `release.py` script is responsible for updating this structure. It takes the generated HTML directory, the version number, and the @@ -174,31 +193,34 @@ deployment branch name as arguments, and then does the following: 1. It copies the HTML to the branch (deleting an existing directory first if needed). -2. It updates the `latest` symlink to point at the most recent +2. It updates the `latest` directory to be a copy of the most recent version, with all numbered releases being considered more recent than any nightly and real releases being more recent than their RCs. -3. It commits the changes to the branch `deploy`, then switches back - to the original branch. - -A successful push to deploy in this way triggers a GH action that runs -the `overlay.py` script, which is then responsible for creating a new -commit to `postdeploy`, based on `deploy`. This commit includes all -desired overlays. At time of writing, this is just a single file -`static/metadata.js` in each version of the reference manual that +3. It updates the `stable` directory to be a copy of the most recent + non-RC version. +4. It commits the changes to the deployment branch, then switches + back to the original branch. + +A successful push to `deploy` triggers a GH action that runs the +`overlay.py` script, which creates commits to `postdeploy` (based on +`deploy`) and `postdeploy-tutorials` (based on `deploy-tutorials`). +These commits include all desired overlays. At time of writing, this +is just a single file `static/metadata.js` in each version that contains information about whether the version is in fact stable or latest. -A successful push to `postdeploy` in this way triggers a GH Action -which actually publishes the content to netlify. +A successful push to `postdeploy` or `postdeploy-tutorials` triggers a +GH Action which publishes the content to Netlify. ## Overlays The script `overlay.py` computes `postdeploy` from `deploy` any time -`deploy` changes. Its purpose is to add metadata or make in-place -changes to `deploy` content that is best thought of as a unified -overlay on top of the data that exists at the historical tags -`4.19.0`, `4.20.0`, etc. +`deploy` changes, and `postdeploy-tutorials` from `deploy-tutorials` +any time `deploy-tutorials` changes. Its purpose is to add metadata or +make in-place changes to deployed content that is best thought of as a +unified overlay on top of the data that exists at the historical +version tags. Examples of the sorts of things we might like to achieve with this overlay mechanism are: @@ -233,7 +255,7 @@ Therefore we can be careful on both sides: To test `overlay.py` locally before pushing, do the following. -- Ensure branches `deploy` and `postdeploy` exist locally. +- Ensure the deployment branches exist locally. - You'll probably want to do ``` @@ -242,6 +264,10 @@ git checkout deploy git reset --hard remotes/upstream/deploy git checkout postdeploy git reset --hard remotes/upstream/postdeploy +git checkout deploy-tutorials +git reset --hard remotes/upstream/deploy-tutorials +git checkout postdeploy-tutorials +git reset --hard remotes/upstream/postdeploy-tutorials ``` - From the `reference-manual` checkout directory, on branch `main`, @@ -249,7 +275,8 @@ git reset --hard remotes/upstream/postdeploy you've made) run ```shell -python3 -B deploy/overlay.py . deploy postdeploy +python3 -B deploy/overlay.py . deploy postdeploy --site-dir reference +python3 -B deploy/overlay.py . deploy-tutorials postdeploy-tutorials --site-dir tutorials ``` - Inspect whatever `postdeploy` results you're interested in, e.g. diff --git a/Tutorial.lean b/Tutorial.lean new file mode 100644 index 000000000..6f892783b --- /dev/null +++ b/Tutorial.lean @@ -0,0 +1,7 @@ +/- +Copyright (c) 2025 Lean FRO LLC. All rights reserved. +Released under Apache 2.0 license as described in the file LICENSE. +Author: David Thrane Christiansen +-/ +import Tutorial.VCGen +import Tutorial.Grind.IndexMap diff --git a/Manual/Grind/ExtendedExamples/IndexMap.lean b/Tutorial/Grind/IndexMap.lean similarity index 93% rename from Manual/Grind/ExtendedExamples/IndexMap.lean rename to Tutorial/Grind/IndexMap.lean index 8bfb4bb7c..cae3f7b43 100644 --- a/Manual/Grind/ExtendedExamples/IndexMap.lean +++ b/Tutorial/Grind/IndexMap.lean @@ -5,13 +5,14 @@ Author: Leo de Moura, Kim Morrison -/ import VersoManual +import VersoTutorial import Lean.Parser.Term import Manual.Meta -open Verso.Genre Manual +open Verso.Genre Manual Tutorial open Verso.Genre.Manual.InlineLean hiding module open Verso.Doc.Elab (CodeBlockExpander) open Verso.Code.External @@ -30,8 +31,12 @@ set_option verso.exampleProject "." set_option verso.exampleModule "IndexMapGrind" -#doc (Manual) "`IndexMap`" => - +#doc (Tutorial) "Using `grind` for Ordered Maps" => +%%% +slug := "grind-index-map" +summary := "A demonstration of how to use `grind` to automate essentially all proofs in a new data structure, with an interface that finds proofs automatically." +exampleStyle := .inlineLean `IndexMap +%%% In this section we'll build an example of a new data structure and basic API for it, illustrating the use of {tactic}`grind`. The example will be derived from Rust's [`indexmap`](https://docs.rs/indexmap/latest/indexmap/) data structure. @@ -60,6 +65,18 @@ Our goals will be: Ideally, we don't even need to see the proofs; they should mostly be handled invisibly by {tactic}`grind`. + +:::paragraph +The first step is to import the necessary data structures: +```anchor imports +import Std.Data.HashMap +``` +::: + +# Skeleton + +:::displayOnly + To begin with, we'll write out a skeleton of what we want to achieve, liberally using {lean}`sorry` as a placeholder for all proofs. In particular, this version makes no use of {tactic}`grind`. @@ -212,6 +229,9 @@ theorem findIdx_insert_self end IndexMap ``` +::: + +# Header 2 Let's get started. We'll aspire to never writing a proof by hand, and the first step of that is to install auto-parameters for the `size_keys` and `WF` field, @@ -219,6 +239,8 @@ so we can omit these fields whenever `grind` can prove them. While we're modifying the definition of `IndexMap` itself, let's make all the fields private, since we're planning on having complete encapsulation. ```anchor IndexMap +open Std + structure IndexMap (α : Type u) (β : Type v) [BEq α] [Hashable α] where private indices : HashMap α Nat @@ -229,6 +251,14 @@ structure IndexMap keys[i]? = some a ↔ indices[a]? = some i := by grind ``` +For the rest of this tutorial, the following namespace and variable declarations are in effect: +```anchor variables +namespace IndexMap + +variable {α : Type u} {β : Type v} [BEq α] [Hashable α] +variable {m : IndexMap α β} {a : α} {b : β} {i : Nat} +``` + Let's give {tactic}`grind` access to the definition of `size`, and `size_keys` private field: ```anchor size @[inline] def size (m : IndexMap α β) : Nat := @@ -250,6 +280,21 @@ def emptyWithCapacity (capacity := 8) : IndexMap α β where ``` ::: +:::codeOnly +```anchor Membership +@[inline] def contains (m : IndexMap α β) + (a : α) : Bool := + m.indices.contains a + +instance : Membership α (IndexMap α β) where + mem m a := a ∈ m.indices + +instance {m : IndexMap α β} {a : α} : Decidable (a ∈ m) := + inferInstanceAs (Decidable (a ∈ m.indices)) +``` +::: + +:::displayOnly Our next task is to deal with the {lean}`sorry` in our construction of the original {anchorTerm GetElem?}`GetElem?` instance: ```anchor GetElem? (module := IndexMap) instance : @@ -261,6 +306,7 @@ instance : getElem! m a := m.indices[a]?.bind (m.values[·]?) |>.getD default ``` +::: The goal at this sorry is ``` @@ -331,7 +377,7 @@ However this proof is going to work, we know the following: * It must use the well-formedness condition of the map. * It can't do so without relating `m.indices[a]` and `m.indices[a]?` (because the later is what appears in the well-formedness condition). * The expected relationship there doesn't even hold unless the map `m.indices` satisfies {lean}`LawfulGetElem`, - for which we need {tech}[instances] of {lean}`LawfulBEq α` and {lean}`LawfulHashable α`. + for which we need {tech (remote:="reference")}[instances] of {lean}`LawfulBEq α` and {lean}`LawfulHashable α`. ::: :::TODO @@ -401,7 +447,13 @@ macro_rules | `(tactic| get_elem_tactic_extensible) => `(tactic| grind) ::: :::paragraph -We can now return to constructing our {anchorName GetElem?}`GetElem?` instance, and simply write: +We can now return to constructing our {anchorName GetElem?}`GetElem?` instance. +In order to use the well-formedness condition, {tactic}`grind` must be able to unfold {anchorName size}`size`: +```anchor local_grind_size +attribute [local grind] size +``` +The {anchorTerm local_grind_size}`local` modifier restricts this unfolding to the current file. +With this in place, we can simply write: ```anchor GetElem? instance : GetElem? (IndexMap α β) α β (fun m a => a ∈ m) where getElem m a h := @@ -630,6 +682,23 @@ Trying again with {anchorName eraseSwap}`eraseSwap`, everything goes through cle | none => m ``` +:::codeOnly +```anchor getFindIdx +@[inline] def findIdx? (m : IndexMap α β) (a : α) : Option Nat := + m.indices[a]? + +@[inline] def findIdx (m : IndexMap α β) (a : α) + (h : a ∈ m := by get_elem_tactic) : Nat := + m.indices[a] + +@[inline] def getIdx? (m : IndexMap α β) (i : Nat) : Option β := + m.values[i]? + +@[inline] def getIdx (m : IndexMap α β) (i : Nat) + (h : i < m.size := by get_elem_tactic) : β := + m.values[i] +``` +::: Finally we turn to the verification theorems about the basic operations, relating {anchorName Verification}`getIdx`, {anchorName Verification}`findIdx`, and {anchorName Verification}`insert`. By adding a {anchorTerm Verification}`local grind` annotation allowing {tactic}`grind` to unfold the definitions of these operations, diff --git a/Tutorial/Meta/Theme.lean b/Tutorial/Meta/Theme.lean new file mode 100644 index 000000000..6070f94bd --- /dev/null +++ b/Tutorial/Meta/Theme.lean @@ -0,0 +1,370 @@ +/- +Copyright (c) 2024-2025 Lean FRO LLC. All rights reserved. +Released under Apache 2.0 license as described in the file LICENSE. +Author: David Thrane Christiansen +-/ +import VersoBlog +import VersoWeb.Theme + +import VersoWeb.Components.Footer +import VersoWeb.Components.NavBar + +open Verso Genre Blog Output Html Multi +open Web Components Theme + +namespace LeanLangOrg + +/-- +Default footer configuration with all standard links +-/ +def footer : FooterConfig := { + columns := #[ + -- Get Started column + { + heading := "Get Started" + headingId := some "get-started" + ariaLabel := some "LEAN" + items := #[ + { title := "Install", url := "/install" }, + { title := "Learn", url := "/learn" }, + { title := "Community", url := "/community" }, + { title := "Reservoir", url := "https://reservoir.lean-lang.org/", blank := true } + ] + }, + -- Documentation column + { + heading := "Documentation" + headingId := some "documentation" + ariaLabel := some "Documentation" + items := #[ + { title := "Language reference", url := "/doc/reference/latest/" }, + { title := "Lean API", url := "/doc/api/" }, + { title := "Use cases", url := "/use-cases" }, + { title := "Cite Lean", url := "/learn#how-to-cite-lean" } + ] + }, + -- Resources column + { + heading := "Resources" + headingId := some "resources" + ariaLabel := some "Resources" + items := #[ + { title := "Lean playground", url := "https://live.lean-lang.org/?from=lean", blank := true }, + { title := "VS Code extension", url := "https://marketplace.visualstudio.com/items?itemName=leanprover.lean4", blank := true }, + { title := "Loogle", url := "https://loogle.lean-lang.org/", blank := true }, + { title := "Mathlib", url := "https://github.com/leanprover-community/mathlib4", blank := true } + ] + }, + -- FRO column + { + heading := "FRO" + headingId := some "fro" + ariaLabel := some "FRO" + items := #[ + { title := "Vision", url := "/fro" }, + { title := "Team", url := "/fro/team" }, + { title := "Roadmap", url := "/fro/roadmap/y3" }, + { title := "Contact", url := "/fro/contact" } + ] + }, + -- Policies column + { + heading := "Policies" + headingId := some "policies" + ariaLabel := some "Policies" + items := #[ + { title := "Privacy Policy", url := "/privacy" }, + { title := "Terms of Use", url := "/terms" }, + { title := "Lean Trademark Policy", url := "/trademark-policy" } + ] + } + ] + socialLinks := #[ + { url := "https://bsky.app/profile/lean-lang.org", icon := Icon.blueskyLogo, ariaLabel := some "Bluesky" }, + { url := "https://www.linkedin.com/company/lean-fro", icon := Icon.linkedinLogo, ariaLabel := some "LinkedIn" }, + { url := "https://functional.cafe/@leanprover", icon := Icon.mastodonLogo, ariaLabel := some "Mastodon" }, + { url := "https://x.com/leanprover", icon := Icon.xLogo, ariaLabel := some "X (Twitter)" }, + { url := "https://leanprover.zulipchat.com/", icon := Icon.zulipLogo, ariaLabel := some "Zulip" }, + { url := "https://github.com/leanprover/", icon := Icon.githubLogo, ariaLabel := some "GitHub" } + ] + copyrightText := "© 2025 Lean FRO. All rights reserved." + showThemeSwitcher := true +} + +/-- +Helper to create FRO home navigation item +-/ +def navFroItem (path : Path) : NavBarItem := + { title := .text false "Home" + , url := some "/fro" + , active := path == #["fro"] } + +/-- +Function to get all the items that redirect to pages. +-/ +def getPageItems : TemplateM (Array NavBarItem) := do + let links ← Verso.Web.Util.getDirLinks + return links.map fun (active, url, title) => { title, url, active } + +def isFro (path : Path) : Bool := path[0]?.isEqSome "fro" + +/-- +Build NavBarConfig for FRO section +-/ +def buildFroNavBarConfig : TemplateM NavBarConfig := do + let leftItems ← getPageItems + let path ← currentPath + + let froPathItems (path : Path) : Array NavBarItem := #[ + { title := .text false "About", url := some "/fro/about", active := path == #["fro", "about"] }, + { title := .text false "Team", url := some "/fro/team", active := path == #["fro", "team"] }, + { title := .text false "Roadmap", url := some "/fro/roadmap", active := path == #["fro", "roadmap"] }, + { title := .text false "Contact", url := some "/fro/contact", active := path == #["fro", "contact"] } + ] + + let externalLinks : Array NavBarItem := #[ + { title := .text false "Playground", url := some "https://live.lean-lang.org/?from=lean", blank := true }, + { title := .text false "Reservoir", url := some "https://reservoir.lean-lang.org/", blank := true } + ] + + let rightItems : Array NavBarItem := #[ + { title := Icon.moon, alt := some "Change Theme", classes := some "change-theme" }, + { title := Icon.github, alt := some "Github", url := some "https://github.com/leanprover/lean4", blank := true } + ] + + let menuItems := #[navFroItem path] ++ froPathItems path + + return { + leftItems := leftItems + rightItems := rightItems + menuItems := menuItems + externalLinks := externalLinks + subNavBar := if isFro path then some (SubNavBarConfig.mk (froPathItems path)) else none + } + +def socialMeta : SocialMeta := + { title := "Lean Programming Language", + description := "Lean is an open-source programming language and proof assistant that enables correct, maintainable, and formally verified code.", + image := "https://lean-lang.org/static/png/banner.png", + url := "https://lean-lang.org", + siteName := "Lean Language", + alt := "Lean Programming Language", + articleCreator := "@leanprover", + } + +def headConfig : HeadConfig := + { description := socialMeta.description, + faviconWhite := "https://lean-lang.org/static/favicon-light.ico", + faviconDark := "https://lean-lang.org/static/favicon-dark.ico", + appleTouchIcon := "https://lean-lang.org/static/apple-touch-icon.png", + color := "#3D6AC9" + } + +/-- +Default theme configuration with all design tokens +-/ +def colorTheme : ThemeConfig := { + variables := [ + -- Typography + { name := "font-primary", value := "'Open Sans', Arial, sans-serif" }, + { name := "font-secondary", value := "'Oranienbaum', serif" }, + { name := "fs-xs", value := "0.75rem" }, + { name := "fs-sm", value := "0.875rem" }, + { name := "fs-base", value := "1rem" }, + { name := "fs-md", value := "17px" }, + { name := "fs-lg", value := "1.25rem" }, + { name := "fs-xl", value := "2rem" }, + { name := "fs-2xl", value := "3.3rem" }, + + -- Spacing + { name := "space-1", value := "0.25rem" }, + { name := "space-2", value := "0.5rem" }, + { name := "space-3", value := "0.75rem" }, + { name := "space-4", value := "1rem" }, + { name := "space-5", value := "1.25rem" }, + { name := "space-6", value := "1.5rem" }, + { name := "space-8", value := "2rem" }, + { name := "space-10", value := "2.5rem" }, + { name := "space-12", value := "3rem" }, + { name := "space-13", value := "3.5rem" }, + { name := "space-14", value := "4rem" }, + { name := "space-16", value := "5rem" }, + + -- Semantic spacing + { name := "gap-sm", value := "var(--space-2)" }, + { name := "gap-md", value := "10px" }, + { name := "gap-lg", value := "30px" }, + { name := "gap-xl", value := "100px" }, + + -- Section padding + { name := "section-padding", value := "var(--space-10)" }, + { name := "section-padding-top", value := "var(--space-16)" }, + + -- Border Radius + { name := "radius-sm", value := "0.25rem" }, + { name := "radius-md", value := "0.5rem" }, + { name := "radius-lg", value := "1rem" }, + { name := "radius-pill", value := "9999px" }, + + -- Sizes + { name := "container-width", value := "1240px" }, + { name := "logo-size", value := "1.25rem" }, + { name := "logo-footer-size", value := "60px" }, + { name := "icon-size", value := "64px" }, + + -- Layout + { name := "nav-padding-y", value := "var(--space-6)" }, + { name := "nav-padding-x", value := "10vw" }, + { name := "nav-height", value := "calc(var(--nav-padding-y) * 2 + 2em)" }, + + -- Transitions + { name := "transition-fast", value := "0.2s" }, + { name := "transition-base", value := "0.3s" }, + { name := "transition-slow", value := "0.6s" }, + { name := "transition-delay-none", value := "0s" }, + { name := "transition-delay-small", value := "0.05s" }, + { name := "transition-delay-medium", value := "0.1s" }, + { name := "transition-delay-large", value := "0.15s" }, + + -- Animation + { name := "animation-delay", value := "10000ms" }, + + -- Z-Index + { name := "z-below", value := "-1" }, + { name := "z-normal", value := "0" }, + { name := "z-above", value := "1" }, + { name := "z-header", value := "1000" }, + + -- Colors + { name := "color-surface", value := "#fff" }, + { name := "color-primary", value := "#386EE0" }, + { name := "color-primary-focus", value := "#1D4ED8" }, + { name := "color-primary-light", value := "#4a90e2" }, + { name := "color-secondary", value := "#607D8B" }, + { name := "color-text", value := "#333" }, + { name := "color-text-contrast", value := "white" }, + { name := "color-text-light", value := "#64748b" }, + { name := "color-muted", value := "#607D8B" }, + { name := "color-bg", value := "#F9FBFD" }, + { name := "color-bg-translucent", value := "rgba(249, 251, 253, 0.81)" }, + { name := "color-white", value := "#fff" }, + { name := "color-border", value := "#E4EBF3" }, + { name := "color-border-nav", value := "#E4EBF3" }, + { name := "color-border-light", value := "#D1D9E2" }, + { name := "color-hover", value := "rgba(56, 110, 224, 0.08)" }, + { name := "color-link-hover", value := "#0073e6" }, + { name := "color-shadow", value := "rgba(35, 55, 139, 0.1)" }, + + -- Components + { name := "btn-bg", value := "var(--color-primary)" }, + { name := "btn-text", value := "var(--color-white)" }, + { name := "btn-font", value := "var(--font-primary)" }, + { name := "btn-radius", value := "var(--radius-md)" }, + + -- Card specific + { name := "card-bg", value := "var(--color-white)" }, + { name := "card-border", value := "var(--color-border-light)" }, + + -- Testimonial specific + { name := "testimonial-bg", value := "var(--color-primary)" }, + { name := "testimonial-text", value := "var(--color-white)" } + ], + + darkVariables := [ + + -- Dark theme color overrides + { name := "color-surface", value := "#121212" }, + { name := "color-primary", value := "#3b94ff" }, + { name := "color-primary-focus", value := "#669df6" }, + { name := "color-primary-light", value := "#6aadfe" }, + { name := "color-secondary", value := "#aabfc9" }, + { name := "color-text", value := "#eee" }, + { name := "color-text-light", value := "#bbb" }, + { name := "color-text-contrast", value := "white" }, + { name := "color-muted", value := "#90a4ae" }, + { name := "color-bg", value := "#181818" }, + { name := "color-bg-translucent", value := "rgba(24, 24, 24, 0.85)" }, + { name := "color-white", value := "#1e1e1e" }, + { name := "color-border", value := "#333" }, + { name := "color-border-nav", value := "#333" }, + { name := "color-border-light", value := "#444" }, + { name := "color-hover", value := "rgba(255, 255, 255, 0.08)" }, + { name := "color-link-hover", value := "#4d9efc" }, + { name := "color-shadow", value := "rgba(0, 0, 0, 0.5)" }, + + -- Component overrides + { name := "btn-bg", value := "var(--color-primary)" }, + { name := "btn-text", value := "var(--color-white)" }, + { name := "card-bg", value := "#1f1f1f" }, + { name := "card-border", value := "#2a2a2a" }, + { name := "testimonial-bg", value := "#2e3a59" }, + { name := "testimonial-text", value := "#fff" } + ] +} + +/-- +Lean-specific page type detection functions. +-/ + +def isMarkdownPage : Path → Bool + | _ => true + +def indexPage : Path → Bool + | _ => false + +def needsTitle : Path → Bool + | #["learn"] | #["install"] | #["404"] => false + | _ => true + +def isInstallPage (path : Path) : Bool := + path[0]?.isEqSome "install" + +def isUseCases : Path → Bool + | #["use-cases"] => true + | _ => false + +def isRoadmap : Path → Bool + | #["fro", "roadmap"] => true + | _ => false + +def isPagePost : Path → Bool + | #["use-cases", _] | #["fro", "roadmap", _] => true + | _ => false + + +/-- +Lean-specific post configuration. +-/ +def postConfig : PostConfig := + { hasSpecialStyling := fun path => if isFro path then some "fro" else none } + +/-- +Lean website layout configuration. +-/ +def layoutConfig : LayoutConfig := + { isMarkdownPage := isMarkdownPage, + isIndexPage := indexPage, + needsTitle := needsTitle, + isPagePost := isPagePost, + postConfig := postConfig, + hasSpecialStyling := fun path => if isFro path then some "fro" else if path.isEmpty then "tutorials" else none, + renderPostList := fun path html => + if isUseCases path then + {{