Skip to content

Commit 520cdb2

Browse files
authored
feat: do not have meta imply partial (#11587)
This PR adjusts the new `meta` keyword of the experimental module system not to imply `partial` for general consistency. As the previous behavior can create confusion return types that are not known to be `Nonempty` and few `def`s should be `meta` in the first case, this special case does not appear to be worth the minor convenience.
1 parent 9f74e71 commit 520cdb2

File tree

2 files changed

+6
-27
lines changed

2 files changed

+6
-27
lines changed

src/Lean/Elab/DeclModifiers.lean

Lines changed: 0 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -103,15 +103,6 @@ def Modifiers.isPartial : Modifiers → Bool
103103
| { recKind := .partial, .. } => true
104104
| _ => false
105105

106-
/--
107-
Whether the declaration is explicitly `partial` or should be considered as such via `meta`. In the
108-
latter case, elaborators should not produce an error if partiality is unnecessary.
109-
-/
110-
def Modifiers.isInferredPartial : Modifiers → Bool
111-
| { recKind := .partial, .. } => true
112-
| { computeKind := .meta, .. } => true
113-
| _ => false
114-
115106
def Modifiers.isNonrec : Modifiers → Bool
116107
| { recKind := .nonrec, .. } => true
117108
| _ => false

src/Lean/Elab/PreDefinition/Main.lean

Lines changed: 6 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -329,25 +329,13 @@ def addPreDefinitions (docCtx : LocalContext × LocalInstances) (preDefs : Array
329329
else if preDefs.any (·.modifiers.isUnsafe) then
330330
addAndCompileUnsafe docCtx preDefs
331331
preDefs.forM (·.termination.ensureNone "unsafe")
332+
else if preDefs.any (·.modifiers.isPartial) then
333+
for preDef in preDefs do
334+
if preDef.modifiers.isPartial && !(← whnfD preDef.type).isForall then
335+
withRef preDef.ref <| throwError "invalid use of `partial`, `{preDef.declName}` is not a function{indentExpr preDef.type}"
336+
addAndCompilePartial docCtx preDefs
337+
preDefs.forM (·.termination.ensureNone "partial")
332338
else
333-
-- Consider partial if `partial` was given explicitly, or implied and no termination hint
334-
-- was given
335-
if preDefs.any (·.modifiers.isPartial) ||
336-
preDefs.any (·.modifiers.isInferredPartial) && !preDefs.any (·.termination.isNotNone) then
337-
let mut isPartial := true
338-
for preDef in preDefs do
339-
if !(← whnfD preDef.type).isForall then
340-
if preDef.modifiers.isPartial then
341-
withRef preDef.ref <| throwError "invalid use of `partial`, `{preDef.declName}` is not a function{indentExpr preDef.type}"
342-
else
343-
-- `meta` should not imply `partial` in this case
344-
isPartial := false
345-
346-
if isPartial then
347-
addAndCompilePartial docCtx preDefs
348-
preDefs.forM (·.termination.ensureNone "partial")
349-
continue
350-
351339
ensureFunIndReservedNamesAvailable preDefs
352340
try
353341
checkCodomainsLevel preDefs

0 commit comments

Comments
 (0)