lean4-htt/Lake/Build/Data.lean
2022-06-24 17:04:42 -04:00

67 lines
2.3 KiB
Text
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

/-
Copyright (c) 2022 Mac Malone. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Mac Malone
-/
import Lake.Build.Key
import Lake.Util.DynamicType
open Lean
namespace Lake
/--
Type of build data associated with a module facet in the Lake build store.
For example a transitive × direct import pair for `imports` or an active build
target for `lean.c`.
It is a dynamic type, meaning additional alternatives can be add lazily
as needed.
-/
opaque ModuleData (facet : WfName) : Type
/-- Type of build data associated with package facets (e.g., `extraDep`). -/
opaque PackageData (facet : WfName) : Type
/-- Type of build data associated with Lake targets (e.g., `extern_lib`). -/
opaque TargetData (key : BuildKey) : Type
/--
Type of the build data associated with a key in the Lake build store.
It is dynamic type composed of the three separate dynamic types for modules,
packages, and targets.
-/
def BuildData (key : BuildKey) :=
if key.isModuleKey then
ModuleData key.facet
else if key.isPackageKey then
PackageData key.facet
else
TargetData key
instance (k : ModuleBuildKey f)
[t : DynamicType ModuleData f α] : DynamicType BuildData k α where
eq_dynamic_type := by
unfold BuildData
simp [k.is_module_key, k.facet_eq_fixed, t.eq_dynamic_type]
instance (k : PackageBuildKey f)
[t : DynamicType PackageData f α] : DynamicType BuildData k α where
eq_dynamic_type := by
unfold BuildData, BuildKey.isModuleKey
have has_pkg := of_decide_eq_true (of_decide_eq_true k.is_package_key |>.1)
simp [has_pkg, k.is_package_key, k.facet_eq_fixed, t.eq_dynamic_type]
/-- Macro for declaring new `PackageData`. -/
scoped macro (name := packageDataDecl) doc?:optional(Parser.Command.docComment)
"package_data " id:ident " : " ty:term : command => do
let dty := mkCIdentFrom (← getRef) ``PackageData
let key := WfName.quoteFrom id <| WfName.ofName <| id.getId
`($[$doc?]? dynamic_data $id : $dty $key := $ty)
/-- Macro for declaring new `ModuleData`. -/
scoped macro (name := moduleDataDecl) doc?:optional(Parser.Command.docComment)
"module_data " id:ident " : " ty:term : command => do
let dty := mkCIdentFrom (← getRef) ``ModuleData
let key := WfName.quoteFrom id <| WfName.ofName <| id.getId
`($[$doc?]? dynamic_data $id : $dty $key := $ty)