Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions src/LeanIR.lean
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ import all Lean.Util.Path
import all Lean.Environment
import Lean.Compiler.Options
import Lean.Compiler.IR.CompilerM
import Lean.Compiler.ModPkgExt

import all Lean.Compiler.CSimpAttr
import Lean.Compiler.LCNF.EmitC
Expand Down Expand Up @@ -90,6 +91,9 @@ public def main (args : List String) : IO UInt32 := do
-- level exported because otherwise we would try to load the current module's `.ir`
finalizeImport (leakEnv := true) (loadExts := false) (level := .exported) (loadIRSig := true) s imports opts
let env := env.setMainModule modName
-- As the environment imports the module to compile, it does not inherit its package.
-- Take it from the setup.
let env := env.setModulePackage setup.package?
Comment on lines +94 to +96

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@Kha This changes non-Lake code and is thus probably the bit that most needs your review.


let initExt {α β σ} [Inhabited σ] (ext : PersistentEnvExtension α β σ) (env : Environment) : IO Environment := do
let s := ext.toEnvExtension.getState env
Expand Down
30 changes: 13 additions & 17 deletions src/lake/Lake/Build/Actions.lean
Original file line number Diff line number Diff line change
Expand Up @@ -26,14 +26,26 @@ open Lean hiding SearchPath

namespace Lake

public def compileLeanIR
(setupFile irFile cFile : FilePath)
(leanPath : SearchPath := [])
(leanir : FilePath := "leanir")
: LogIO Unit := do
createParentDirs irFile
createParentDirs cFile
proc {
cmd := leanir.toString
args := #[setupFile.toString, irFile.toString, cFile.toString]
env := #[("LEAN_PATH", leanPath.toString)]
}

public def compileLeanModule
(leanFile relLeanFile : FilePath)
(setup : ModuleSetup) (setupFile : FilePath)
(arts : ModuleArtifacts)
(leanArgs : Array String := #[])
(leanPath : SearchPath := [])
(lean : FilePath := "lean")
(leanir : FilePath := "leanir")
: LogIO Unit := do
let mut args := leanArgs.push leanFile.toString
if let some oleanFile := arts.olean? then
Expand Down Expand Up @@ -91,22 +103,6 @@ public def compileLeanModule
failure
else if out.exitCode ≠ 0 || hasErrors then
error s!"Lean exited with code {out.exitCode}"
if postponeCompile then
if let (some irFile, some cFile) := (arts.ir?, arts.c?) then
createParentDirs irFile
createParentDirs cFile
try
proc {
cmd := leanir.toString
args := #[setupFile.toString, irFile.toString, cFile.toString]
env := #[
("LEAN_PATH", leanPath.toString)
]
}
catch e =>
if let some oleanFile := arts.olean? then
removeFileIfExists oleanFile
throw e

public def compileO
(oFile srcFile : FilePath)
Expand Down
24 changes: 21 additions & 3 deletions src/lake/Lake/Build/Facets.lean
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,10 @@ public structure ModuleImportInfo where
allTransTrace : BuildTrace
/-- Transitive import trace for an `import` of the module without the module system enabled. -/
legacyTransTrace : BuildTrace
/-- The trace produced by mixing the `leanir` traces of `directArts` with their transitive imports. -/
irSigTrace : BuildTrace
/-- Transitive import trace for a `leanir` run over an importer of the module. -/
irSigTransTrace : BuildTrace
deriving Inhabited

/-- **For internal use only.** Information about the imports of this module. -/
Expand All @@ -93,28 +97,39 @@ public structure ModuleExportInfo where
arts : ImportArtifacts
/-- The trace of the module's public olean. -/
artsTrace : BuildTrace
/-- The trace of the module's public olean and IR. -/
/-- Transitive import trace for an `import` of the module with the module system enabled. -/
transTrace : BuildTrace
deriving Inhabited

/-- Information useful to importers of a module. Includes IR. -/
public structure ModuleMetaExportInfo extends ModuleExportInfo where
/-- The trace of the module's public olean and IR (i.e., what a `meta import` needs). -/
metaArtsTrace : BuildTrace
/-- The trace of the module's public olean and IR signature (i.e., what `leanir` needs). -/
irSigArtsTrace : BuildTrace
/--
Artifacts directly needed for an `import` of the module from a module without the module
system enabled or `import all` of the module from a module with it enabled.
-/
allArts : ImportArtifacts
/-- The trace produced by mixing the traces of `allArts`. -/
allArtsTrace : BuildTrace
/-- Transitive import trace for an `import` of the module with the module system enabled. -/
transTrace : BuildTrace
/-- Transitive import trace for a `meta import` of the module. -/
metaTransTrace : BuildTrace
/-- Transitive import trace for an `import all` of the module. -/
allTransTrace : BuildTrace
/-- Transitive import trace for an `import` of the module without the module system enabled. -/
legacyTransTrace : BuildTrace
/-- Transitive import trace for a `leanir` run over an importer of the module. -/
irSigTransTrace : BuildTrace
deriving Inhabited

/-- **For internal use only.** Information useful to importers of this module. -/
builtin_facet exportInfo : Module => ModuleExportInfo

/-- **For internal use only.** Information useful to `meta` importers of this module. -/
builtin_facet metaExportInfo : Module => ModuleMetaExportInfo

/-- Artifacts directly needed for an `import` of this module with the module system enabled. -/
builtin_facet importArts : Module => ImportArtifacts

Expand All @@ -132,6 +147,9 @@ Its trace just includes its dependencies.
-/
builtin_facet leanArts : Module => ModuleOutputArtifacts

/-- The artifacts of a Lean module's code generation (e.g., `.ir.sig`, `.ir`, `.c`). -/
builtin_facet irArts : Module => ModuleOutputArtifacts

/-- A compressed archive (produced via `leantar`) of the module's build artifacts. -/
builtin_facet ltar : Module => FilePath

Expand Down
7 changes: 7 additions & 0 deletions src/lake/Lake/Build/Infos.lean
Original file line number Diff line number Diff line change
Expand Up @@ -83,6 +83,7 @@ builtin_facet imports : Module => Array Module
/-- Dynamic information computed about a module before building. -/
public structure ModulePreSetup where
trace : BuildTrace
irSigTrace : BuildTrace
srcMTime : MTime
srcFile : FilePath
isModule : Bool
Expand Down Expand Up @@ -181,6 +182,9 @@ namespace Module
@[inherit_doc exportInfoFacet] public abbrev exportInfo (self : Module) :=
self.facetCore exportInfoFacet

@[inherit_doc metaExportInfoFacet] public abbrev metaExportInfo (self : Module) :=
self.facetCore metaExportInfoFacet

@[inherit_doc importArtsFacet] public abbrev importArts (self : Module) :=
self.facetCore importArtsFacet

Expand All @@ -190,6 +194,9 @@ namespace Module
@[inherit_doc leanArtsFacet] public abbrev leanArts (self : Module) :=
self.facetCore leanArtsFacet

@[inherit_doc irArtsFacet] public abbrev irArts (self : Module) :=
self.facetCore irArtsFacet

@[inherit_doc oleanFacet] public abbrev olean (self : Module) :=
self.facetCore oleanFacet

Expand Down
Loading
Loading