-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathUnsupportedOnTarget.lean
More file actions
51 lines (42 loc) · 1.7 KB
/
Copy pathUnsupportedOnTarget.lean
File metadata and controls
51 lines (42 loc) · 1.7 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
/-
Copyright (c) 2026 Lean FRO, LLC. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Siddharth Bhat
-/
module
prelude
public import Lean.MonadEnv
public section
namespace Lean.Compiler
structure UnsupportedOnTargetData where
triplePattern : String
reason : String
deriving Inhabited, BEq
@[expose] def UnsupportedOnTargetMap := NameMap (Array UnsupportedOnTargetData)
deriving EmptyCollection, Inhabited
initialize unsupportedOnTargetExt :
SimplePersistentEnvExtension (Name × UnsupportedOnTargetData) UnsupportedOnTargetMap ←
let insert := fun (m : UnsupportedOnTargetMap) (e : Name × UnsupportedOnTargetData) =>
m.insert e.1 (((m.find? e.1).getD #[]).push e.2)
registerSimplePersistentEnvExtension {
addImportedFn := mkStateFromImportedEntries insert {}
addEntryFn := insert
toArrayFn := (·.toArray)
}
/-- Glob-match a triple against a pattern; only `*` (any substring) is supported. -/
partial def tripleMatches (pattern triple : String) : Bool :=
go pattern.toList triple.toList
where
go : List Char → List Char → Bool
| [], ts => ts.isEmpty
| '*' :: ps, ts => go ps ts || (!ts.isEmpty && go ('*' :: ps) ts.tail!)
| _ :: _, [] => false
| p :: ps, t :: ts => p == t && go ps ts
def collectUnsupportedOnTarget (env : Environment) (triple : String)
(usedSet : NameSet) : Array (Name × UnsupportedOnTargetData) :=
unsupportedOnTargetExt.getState env |>.foldl (init := #[]) fun acc n ds =>
if usedSet.contains n then
ds.foldl (init := acc) fun a d =>
if tripleMatches d.triplePattern triple then a.push (n, d) else a
else acc
end Lean.Compiler