fix: constant => opaque issues

This commit is contained in:
Leonardo de Moura 2022-06-14 17:19:54 -07:00
parent fb55ec29e1
commit f6d1e48cb8
17 changed files with 41 additions and 41 deletions

View file

@ -58,7 +58,7 @@ def popFront (s : Subarray α) : Subarray α :=
-- TODO: provide reference implementation
@[implementedBy Subarray.forInUnsafe]
protected constant forIn {α : Type u} {β : Type v} {m : Type v → Type w} [Monad m] (s : Subarray α) (b : β) (f : α → β → m (ForInStep β)) : m β :=
protected opaque forIn {α : Type u} {β : Type v} {m : Type v → Type w} [Monad m] (s : Subarray α) (b : β) (f : α → β → m (ForInStep β)) : m β :=
pure b
instance : ForIn m (Subarray α) α where

View file

@ -11,15 +11,15 @@ import Init.Data.Array.Basic
namespace Lean
@[extern c inline "lean_box(LEAN_VERSION_MAJOR)"]
private constant version.getMajor (u : Unit) : Nat
private opaque version.getMajor (u : Unit) : Nat
def version.major : Nat := version.getMajor ()
@[extern c inline "lean_box(LEAN_VERSION_MINOR)"]
private constant version.getMinor (u : Unit) : Nat
private opaque version.getMinor (u : Unit) : Nat
def version.minor : Nat := version.getMinor ()
@[extern c inline "lean_box(LEAN_VERSION_PATCH)"]
private constant version.getPatch (u : Unit) : Nat
private opaque version.getPatch (u : Unit) : Nat
def version.patch : Nat := version.getPatch ()
@[extern "lean_get_githash"]

View file

@ -88,15 +88,15 @@ set_option compiler.extract_closed false in
@[inline] unsafe def unsafeIO (fn : IO α) : Except IO.Error α :=
unsafeEIO fn
@[extern "lean_io_timeit"] constant timeit (msg : @& String) (fn : IO α) : IO α
@[extern "lean_io_allocprof"] constant allocprof (msg : @& String) (fn : IO α) : IO α
@[extern "lean_io_timeit"] opaque timeit (msg : @& String) (fn : IO α) : IO α
@[extern "lean_io_allocprof"] opaque allocprof (msg : @& String) (fn : IO α) : IO α
/- Programs can execute IO actions during initialization that occurs before
the `main` function is executed. The attribute `[init <action>]` specifies
which IO action is executed to set the value of an opaque constant.
The action `initializing` returns `true` iff it is invoked during initialization. -/
@[extern "lean_io_initializing"] constant IO.initializing : BaseIO Bool
@[extern "lean_io_initializing"] opaque IO.initializing : BaseIO Bool
namespace BaseIO

View file

@ -9,9 +9,9 @@ import Init.Data.Nat.Basic
namespace System
namespace Platform
@[extern "lean_system_platform_windows"] constant getIsWindows : Unit → Bool
@[extern "lean_system_platform_osx"] constant getIsOSX : Unit → Bool
@[extern "lean_system_platform_emscripten"] constant getIsEmscripten : Unit → Bool
@[extern "lean_system_platform_windows"] opaque getIsWindows : Unit → Bool
@[extern "lean_system_platform_osx"] opaque getIsOSX : Unit → Bool
@[extern "lean_system_platform_emscripten"] opaque getIsEmscripten : Unit → Bool
def isWindows : Bool := getIsWindows ()
def isOSX : Bool := getIsOSX ()

View file

@ -9,14 +9,14 @@ open System
namespace Lean.Compiler.FFI
@[extern "lean_get_leanc_extra_flags"]
private constant getLeancExtraFlags : Unit → String
private opaque getLeancExtraFlags : Unit → String
/-- Return C compiler flags for including Lean's headers. -/
def getCFlags (leanSysroot : FilePath) : Array String :=
#["-I", (leanSysroot / "include").toString] ++ (getLeancExtraFlags ()).trim.splitOn
@[extern "lean_get_linker_flags"]
private constant getBuiltinLinkerFlags (linkStatic : Bool) : String
private opaque getBuiltinLinkerFlags (linkStatic : Bool) : String
/-- Return linker flags for linking against Lean's libraries. -/
def getLinkerFlags (leanSysroot : FilePath) (linkStatic := true) : Array String :=

View file

@ -26,11 +26,11 @@ private def isIOUnit (type : Expr) : Bool :=
Return `false` if the initializer is not available as native code.
Initializers do not have corresponding Lean definitions, so they cannot be interpreted in this case. -/
@[extern "lean_run_mod_init"]
unsafe constant runModInit (mod : Name) : IO Bool
unsafe opaque runModInit (mod : Name) : IO Bool
/-- Run the initializer for `decl` and store its value for global access. Should only be used while importing. -/
@[extern "lean_run_init"]
unsafe constant runInit (env : @& Environment) (opts : @& Options) (decl initDecl : @& Name) : IO Unit
unsafe opaque runInit (env : @& Environment) (opts : @& Options) (decl initDecl : @& Name) : IO Unit
unsafe def registerInitAttrUnsafe (attrName : Name) (runAfterImport : Bool) : IO (ParametricAttribute Name) :=
registerParametricAttribute {

View file

@ -48,7 +48,7 @@ and calling `precheck` recursively on nested terms, potentially with an extended
Macros without registered precheck hook are unfolded, and identifier-less syntax is ultimately assumed to be well-formed.",
valueTypeName := ``Precheck
} `Lean.Elab.Term.Quotation.precheckAttribute
@[builtinInit mkPrecheckAttribute] constant precheckAttribute : KeyedDeclsAttribute Precheck
@[builtinInit mkPrecheckAttribute] opaque precheckAttribute : KeyedDeclsAttribute Precheck
partial def precheck : Precheck := fun stx => do
if let p::_ := precheckAttribute.getValues (← getEnv) stx.getKind then

View file

@ -110,7 +110,7 @@ protected def getMainModule : TacticM Name := do pure (← getEnv).mai
unsafe def mkTacticAttribute : IO (KeyedDeclsAttribute Tactic) :=
mkElabAttribute Tactic `Lean.Elab.Tactic.tacticElabAttribute `builtinTactic `tactic `Lean.Parser.Tactic `Lean.Elab.Tactic.Tactic "tactic"
@[builtinInit mkTacticAttribute] constant tacticElabAttribute : KeyedDeclsAttribute Tactic
@[builtinInit mkTacticAttribute] opaque tacticElabAttribute : KeyedDeclsAttribute Tactic
def mkTacticInfo (mctxBefore : MetavarContext) (goalsBefore : List MVarId) (stx : Syntax) : TacticM Info :=
return Info.ofTacticInfo {

View file

@ -11,7 +11,7 @@ open Meta
macro "declare_config_elab" elabName:ident type:ident : command =>
`(unsafe def evalUnsafe (e : Expr) : TermElabM $type :=
Term.evalExpr $type ``$type e
@[implementedBy evalUnsafe] constant eval (e : Expr) : TermElabM $type
@[implementedBy evalUnsafe] opaque eval (e : Expr) : TermElabM $type
def $elabName (optConfig : Syntax) : TermElabM $type := do
if optConfig.isNone then
return { : $type }

View file

@ -231,7 +231,7 @@ def toNat (lvl : Level) : Option Nat :=
| _ => none
@[extern "lean_level_eq"]
protected constant beq (a : @& Level) (b : @& Level) : Bool
protected opaque beq (a : @& Level) (b : @& Level) : Bool
instance : BEq Level := ⟨Level.beq⟩

View file

@ -307,12 +307,12 @@ def useEtaStruct (inductName : Name) : MetaM Bool := do
/-- Reduces an expression to its Weak Head Normal Form.
This is when the topmost expression has been fully reduced,
but may contain subexpressions which have not been reduced. -/
@[extern 6 "lean_whnf"] constant whnf : Expr → MetaM Expr
@[extern 6 "lean_whnf"] opaque whnf : Expr → MetaM Expr
/-- Returns the inferred type of the given expression, or fails if it is not type-correct. -/
@[extern 6 "lean_infer_type"] constant inferType : Expr → MetaM Expr
@[extern 7 "lean_is_expr_def_eq"] constant isExprDefEqAux : Expr → Expr → MetaM Bool
@[extern 7 "lean_is_level_def_eq"] constant isLevelDefEqAux : Level → Level → MetaM Bool
@[extern 6 "lean_synth_pending"] protected constant synthPending : MVarId → MetaM Bool
@[extern 6 "lean_infer_type"] opaque inferType : Expr → MetaM Expr
@[extern 7 "lean_is_expr_def_eq"] opaque isExprDefEqAux : Expr → Expr → MetaM Bool
@[extern 7 "lean_is_level_def_eq"] opaque isLevelDefEqAux : Level → Level → MetaM Bool
@[extern 6 "lean_synth_pending"] protected opaque synthPending : MVarId → MetaM Bool
def whnfForall (e : Expr) : MetaM Expr := do
let e' ← whnf e

View file

@ -8,15 +8,15 @@ import Lean.Meta.AppBuilder
namespace Lean
@[extern "lean_mk_cases_on"] constant mkCasesOnImp (env : Environment) (declName : @& Name) : Except KernelException Environment
@[extern "lean_mk_rec_on"] constant mkRecOnImp (env : Environment) (declName : @& Name) : Except KernelException Environment
@[extern "lean_mk_no_confusion"] constant mkNoConfusionCoreImp (env : Environment) (declName : @& Name) : Except KernelException Environment
@[extern "lean_mk_below"] constant mkBelowImp (env : Environment) (declName : @& Name) : Except KernelException Environment
@[extern "lean_mk_ibelow"] constant mkIBelowImp (env : Environment) (declName : @& Name) : Except KernelException Environment
@[extern "lean_mk_brec_on"] constant mkBRecOnImp (env : Environment) (declName : @& Name) : Except KernelException Environment
@[extern "lean_mk_binduction_on"] constant mkBInductionOnImp (env : Environment) (declName : @& Name) : Except KernelException Environment
@[extern "lean_mk_cases_on"] opaque mkCasesOnImp (env : Environment) (declName : @& Name) : Except KernelException Environment
@[extern "lean_mk_rec_on"] opaque mkRecOnImp (env : Environment) (declName : @& Name) : Except KernelException Environment
@[extern "lean_mk_no_confusion"] opaque mkNoConfusionCoreImp (env : Environment) (declName : @& Name) : Except KernelException Environment
@[extern "lean_mk_below"] opaque mkBelowImp (env : Environment) (declName : @& Name) : Except KernelException Environment
@[extern "lean_mk_ibelow"] opaque mkIBelowImp (env : Environment) (declName : @& Name) : Except KernelException Environment
@[extern "lean_mk_brec_on"] opaque mkBRecOnImp (env : Environment) (declName : @& Name) : Except KernelException Environment
@[extern "lean_mk_binduction_on"] opaque mkBInductionOnImp (env : Environment) (declName : @& Name) : Except KernelException Environment
variable {m} [Monad m] [MonadEnv m] [MonadError m] [MonadOptions m]
variable [Monad m] [MonadEnv m] [MonadError m] [MonadOptions m]
@[inline] private def adaptFn (f : Environment → Name → Except KernelException Environment) (declName : Name) : m Unit := do
match f (← getEnv) declName with

View file

@ -113,7 +113,7 @@ unsafe def mkDelabAttribute : IO (KeyedDeclsAttribute Delab) :=
is tried first.",
valueTypeName := `Lean.PrettyPrinter.Delaborator.Delab
} `Lean.PrettyPrinter.Delaborator.delabAttribute
@[builtinInit mkDelabAttribute] constant delabAttribute : KeyedDeclsAttribute Delab
@[builtinInit mkDelabAttribute] opaque delabAttribute : KeyedDeclsAttribute Delab
def getExprKind : DelabM Name := do
let e ← getExpr
@ -267,7 +267,7 @@ to true or `pp.notation` is set to false, it will not be called at all.",
evalKey := fun _ stx => do
resolveGlobalConstNoOverloadCore (← Attribute.Builtin.getId stx)
} `Lean.PrettyPrinter.Delaborator.appUnexpanderAttribute
@[builtinInit mkAppUnexpanderAttribute] constant appUnexpanderAttribute : KeyedDeclsAttribute Unexpander
@[builtinInit mkAppUnexpanderAttribute] opaque appUnexpanderAttribute : KeyedDeclsAttribute Unexpander
end Delaborator

View file

@ -70,7 +70,7 @@ unsafe def mkFormatterAttribute : IO (KeyedDeclsAttribute Formatter) :=
if (builtin && (env.find? id).isSome) || Parser.isValidSyntaxNodeKind env id then pure id
else throwError "invalid [formatter] argument, unknown syntax kind '{id}'"
} `Lean.PrettyPrinter.formatterAttribute
@[builtinInit mkFormatterAttribute] constant formatterAttribute : KeyedDeclsAttribute Formatter
@[builtinInit mkFormatterAttribute] opaque formatterAttribute : KeyedDeclsAttribute Formatter
unsafe def mkCombinatorFormatterAttribute : IO ParserCompiler.CombinatorAttribute :=
ParserCompiler.registerCombinatorAttribute
@ -81,7 +81,7 @@ unsafe def mkCombinatorFormatterAttribute : IO ParserCompiler.CombinatorAttribut
Note that, unlike with [formatter], this is not a node kind since combinators usually do not introduce their own node kinds.
The tagged declaration may optionally accept parameters corresponding to (a prefix of) those of `c`, where `Parser` is replaced
with `Formatter` in the parameter types."
@[builtinInit mkCombinatorFormatterAttribute] constant combinatorFormatterAttribute : ParserCompiler.CombinatorAttribute
@[builtinInit mkCombinatorFormatterAttribute] opaque combinatorFormatterAttribute : ParserCompiler.CombinatorAttribute
namespace Formatter

View file

@ -127,7 +127,7 @@ unsafe def mkParenthesizerAttribute : IO (KeyedDeclsAttribute Parenthesizer) :=
if (builtin && (env.find? id).isSome) || Parser.isValidSyntaxNodeKind env id then pure id
else throwError "invalid [parenthesizer] argument, unknown syntax kind '{id}'"
} `Lean.PrettyPrinter.parenthesizerAttribute
@[builtinInit mkParenthesizerAttribute] constant parenthesizerAttribute : KeyedDeclsAttribute Parenthesizer
@[builtinInit mkParenthesizerAttribute] opaque parenthesizerAttribute : KeyedDeclsAttribute Parenthesizer
abbrev CategoryParenthesizer := (prec : Nat) → Parenthesizer
@ -148,7 +148,7 @@ unsafe def mkCategoryParenthesizerAttribute : IO (KeyedDeclsAttribute CategoryPa
if Parser.isParserCategory env id then pure id
else throwError "invalid [categoryParenthesizer] argument, unknown parser category '{toString id}'"
} `Lean.PrettyPrinter.categoryParenthesizerAttribute
@[builtinInit mkCategoryParenthesizerAttribute] constant categoryParenthesizerAttribute : KeyedDeclsAttribute CategoryParenthesizer
@[builtinInit mkCategoryParenthesizerAttribute] opaque categoryParenthesizerAttribute : KeyedDeclsAttribute CategoryParenthesizer
unsafe def mkCombinatorParenthesizerAttribute : IO ParserCompiler.CombinatorAttribute :=
ParserCompiler.registerCombinatorAttribute
@ -159,7 +159,7 @@ unsafe def mkCombinatorParenthesizerAttribute : IO ParserCompiler.CombinatorAttr
Note that, unlike with [parenthesizer], this is not a node kind since combinators usually do not introduce their own node kinds.
The tagged declaration may optionally accept parameters corresponding to (a prefix of) those of `c`, where `Parser` is replaced
with `Parenthesizer` in the parameter types."
@[builtinInit mkCombinatorParenthesizerAttribute] constant combinatorParenthesizerAttribute : ParserCompiler.CombinatorAttribute
@[builtinInit mkCombinatorParenthesizerAttribute] opaque combinatorParenthesizerAttribute : ParserCompiler.CombinatorAttribute
namespace Parenthesizer

View file

@ -27,10 +27,10 @@ unsafe abbrev Object.ptrHash (a : Object) : UInt64 :=
ptrAddrUnsafe a |>.toUInt64
@[extern "lean_sharecommon_eq"]
unsafe constant Object.eq (a b : @& Object) : Bool
unsafe opaque Object.eq (a b : @& Object) : Bool
@[extern "lean_sharecommon_hash"]
unsafe constant Object.hash (a : @& Object) : UInt64
unsafe opaque Object.hash (a : @& Object) : UInt64
unsafe def ObjectMap : Type := @HashMap Object Object ⟨Object.ptrEq⟩ ⟨Object.ptrHash⟩
unsafe def ObjectSet : Type := @HashSet Object ⟨Object.eq⟩ ⟨Object.hash⟩

@ -1 +1 @@
Subproject commit 535822481d9a289b482d7c725bf588ad55f00642
Subproject commit 3fb0c2f110d0ff95c1bd41da0259e8f7e77003c0