Skip to content

Commit 3c90e39

Browse files
authored
refactor: remove satNimSelection two-pass dead code, rename to satSolving (#1651)
1 parent 5c97669 commit 3c90e39

File tree

7 files changed

+25
-83
lines changed

7 files changed

+25
-83
lines changed

src/nimble.nim

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2026,7 +2026,7 @@ proc runVNext*(options: var Options, nimBin: string) {.instrument.} =
20262026
# For non-project-dir develops, solve from each cloned package as root
20272027
if not options.thereIsNimbleFile and developedPkgs.len > 0:
20282028
for rootPkg in developedPkgs:
2029-
options.satResult = initSATResult(satNimSelection)
2029+
options.satResult = initSATResult(satSolving)
20302030
solvePkgs(rootPkg, options, nimBin)
20312031
developFromSolution(rootPkg.basicInfo.name, options, nimBin)
20322032
return
@@ -2041,7 +2041,7 @@ proc runVNext*(options: var Options, nimBin: string) {.instrument.} =
20412041
options.action.packages.len == 0 and options.thereIsNimbleFile
20422042
if isGlobalInstallRoot:
20432043
# nimble install -g: install current project globally
2044-
options.satResult = initSATResult(satNimSelection)
2044+
options.satResult = initSATResult(satSolving)
20452045
rootPackage = getPkgInfoFromDirWithDeclarativeParser(getCurrentDir(), options, nimBin = nimBin)
20462046
solvePkgs(rootPackage, options, nimBin)
20472047
let rootSolvedPkg = SolvedPackage(
@@ -2057,7 +2057,7 @@ proc runVNext*(options: var Options, nimBin: string) {.instrument.} =
20572057
elif options.thereIsNimbleFile and not isGlobalInstall and
20582058
not (findNimbleFile(getCurrentDir(), error = false, options, warn = false).splitFile.name.isNim and
20592059
options.action.typ == actionInstall and options.action.packages.len > 0):
2060-
options.satResult = initSATResult(satNimSelection)
2060+
options.satResult = initSATResult(satSolving)
20612061
options.isFilePathDiscovering = true
20622062
#we need to skip validation for root
20632063
rootPackage = getPkgInfoFromDirWithDeclarativeParser(getCurrentDir(), options, nimBin = nimBin)
@@ -2068,7 +2068,7 @@ proc runVNext*(options: var Options, nimBin: string) {.instrument.} =
20682068
elif options.action.typ == actionInstall:
20692069
#Global install
20702070
for pkg in options.action.packages:
2071-
options.satResult = initSATResult(satNimSelection)
2071+
options.satResult = initSATResult(satSolving)
20722072
# Download package info to pkgcache WITHOUT submodules - submodules are
20732073
# populated in buildtemp during actual install to avoid mutating shared cache (issue #1592)
20742074
# Force git clone (not tarball) so .git and .gitmodules are preserved for buildtemp

src/nimblepkg/declarativeparser.nim

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -684,8 +684,7 @@ proc toRequiresInfo*(pkgInfo: PackageInfo, options: Options, nimBin: string, nim
684684
result.infoKind = pikRequires
685685

686686
if nimbleFileInfo.nestedRequires and options.action.typ != actionCheck: #When checking we want to fail on porpuse
687-
if options.satResult.pass == satNimSelection:
688-
assert nimBin != "", "Cant fallback to the vm parser as there is no nim bin."
687+
assert nimBin != "", "Cant fallback to the vm parser as there is no nim bin."
689688

690689
if options.verbosity <= LowPriority:
691690
for line in nimbleFileInfo.declarativeParserErrorLines:

src/nimblepkg/developfile.nim

Lines changed: 2 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ import sets, sequtils, os, strformat, tables, hashes, strutils, math,
99

1010
import typetraits except distinctBase
1111
import compat/json
12-
import common, cli, packageinfotypes, packageinfo, packageparser, options,
12+
import common, cli, packageinfotypes, packageinfo, options,
1313
version, paths, displaymessages, sha1hashes,
1414
tools, vcstools, syncfile, lockfile, declarativeparser
1515

@@ -172,13 +172,7 @@ proc validatePackage(pkgPath: Path, options: Options, nimBin: string):
172172
## not a valid package directory.
173173

174174
try:
175-
if options.satResult.pass == satNimSelection:
176-
result.pkgInfo = getPkgInfoFromDirWithDeclarativeParser(string(pkgPath), options, nimBin)
177-
#TODO find a way to validate the package, for now just mark the declarativeParser as failed
178-
#as we dont have Nim selected yet.
179-
options.satResult.declarativeParseFailed = true
180-
else:
181-
result.pkgInfo = getPkgInfo(string(pkgPath), options, nimBin, true)
175+
result.pkgInfo = getPkgInfoFromDirWithDeclarativeParser(string(pkgPath), options, nimBin)
182176
except CatchableError as error:
183177
result.error = error
184178

src/nimblepkg/download.nim

Lines changed: 3 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ import parseutils, os, strutils, tables, uri, strformat,
77
import compat/[json, osproc]
88
from algorithm import SortOrder, sorted
99

10-
import packageinfotypes, packageparser, version, tools, common, options, cli,
10+
import packageinfotypes, version, tools, common, options, cli,
1111
sha1hashes, vcstools, displaymessages, packageinfo, config, declarativeparser, packagemetadatafile
1212

1313
const userAgent = "nimble/" & nimbleVersion
@@ -919,10 +919,7 @@ proc downloadPkg*(url: string, verRange: VersionRange,
919919
var pkgInfo: PackageInfo
920920
## Makes sure that the downloaded package's version satisfies the requested
921921
## version range.
922-
pkginfo = if options.satResult.pass == satNimSelection: #TODO later when in vnext we should just use this code path and fallback inside the toRequires if we can
923-
getPkgInfoFromDirWithDeclarativeParser(result.dir, options, nimBin)
924-
else:
925-
getPkgInfo(result.dir, options, nimBin)
922+
pkginfo = getPkgInfoFromDirWithDeclarativeParser(result.dir, options, nimBin)
926923
if pkginfo.basicInfo.version notin verRange:
927924
raise nimbleError(
928925
"Downloaded package's version does not satisfy requested version " &
@@ -999,10 +996,7 @@ proc downloadPkgAsync*(url: string, verRange: VersionRange,
999996
var pkgInfo: PackageInfo
1000997
## Makes sure that the downloaded package's version satisfies the requested
1001998
## version range.
1002-
pkginfo = if options.satResult.pass == satNimSelection: #TODO later when in vnext we should just use this code path and fallback inside the toRequires if we can
1003-
getPkgInfoFromDirWithDeclarativeParser(result.dir, options, nimBin)
1004-
else:
1005-
getPkgInfo(result.dir, options, nimBin)
999+
pkginfo = getPkgInfoFromDirWithDeclarativeParser(result.dir, options, nimBin)
10061000
if pkginfo.basicInfo.version notin verRange:
10071001
raise nimbleError(
10081002
"Downloaded package's version does not satisfy requested version " &

src/nimblepkg/nimblesat.nim

Lines changed: 11 additions & 52 deletions
Original file line numberDiff line numberDiff line change
@@ -90,10 +90,6 @@ proc getMinimalInfo*(pkg: PackageInfo, options: Options): PackageMinimalInfo =
9090
result.name = if pkg.basicInfo.name.isNim: "nim" else: pkg.basicInfo.name
9191
result.version = pkg.basicInfo.version
9292
result.requires = pkg.requires.map(convertNimAliasToNim)
93-
if options.satResult.pass != satNimSelection and
94-
(options.action.typ in {actionLock, actionDeps} or options.hasNimInLockFile()):
95-
# Keep nim requirements with special versions (e.g., #devel, #commit-sha)
96-
result.requires = result.requires.filterIt(not it.isNim or it.ver.kind == verSpecial)
9793
result.url = pkg.metadata.url
9894

9995
proc getMinimalInfo*(nimbleFile: string, options: Options, nimBin: string): PackageMinimalInfo =
@@ -105,10 +101,6 @@ proc getMinimalInfo*(nimbleFile: string, options: Options, nimBin: string): Pack
105101
result.version = pkg.basicInfo.version
106102
result.requires = pkg.requires.map(convertNimAliasToNim)
107103
result.url = pkg.metadata.url
108-
if options.satResult.pass != satNimSelection and
109-
(options.action.typ in {actionLock, actionDeps} or options.hasNimInLockFile()):
110-
# Keep nim requirements with special versions (e.g., #devel, #commit-sha)
111-
result.requires = result.requires.filterIt(not it.isNim or it.ver.kind == verSpecial)
112104

113105
proc getMinimalInfoFromContent*(content: string, name: string, version: Version,
114106
url: string, options: Options): Option[PackageMinimalInfo] =
@@ -127,11 +119,6 @@ proc getMinimalInfoFromContent*(content: string, name: string, version: Version,
127119
var activeFeatures = initTable[PkgTuple, seq[string]]()
128120
pkgInfo.requires = info.getRequires(activeFeatures).map(convertNimAliasToNim)
129121

130-
if options.satResult.pass != satNimSelection and
131-
(options.action.typ in {actionLock, actionDeps} or options.hasNimInLockFile()):
132-
# Keep nim requirements with special versions (e.g., #devel, #commit-sha)
133-
pkgInfo.requires = pkgInfo.requires.filterIt(not it.isNim or it.ver.kind == verSpecial)
134-
135122
return some(pkgInfo)
136123

137124
proc hasVersion*(packageVersions: PackageVersions, pv: PkgTuple): bool =
@@ -702,10 +689,7 @@ proc downloadPkgFromUrl*(pv: PkgTuple, options: Options, doPrompt = false, nimBi
702689

703690
proc downloadPkInfoForPv*(pv: PkgTuple, options: Options, doPrompt = false, nimBin: string): PackageInfo =
704691
let downloadRes = downloadPkgFromUrl(pv, options, doPrompt, nimBin)
705-
if options.satResult.pass in {satNimSelection}:
706-
result = getPkgInfoFromDirWithDeclarativeParser(downloadRes[0].dir, options, nimBin)
707-
else:
708-
result = getPkgInfo(downloadRes[0].dir, options, nimBin, forValidation = false, onlyMinimalInfo = false)
692+
result = getPkgInfoFromDirWithDeclarativeParser(downloadRes[0].dir, options, nimBin)
709693

710694
proc getAllNimReleases(options: Options, nimVersion: Option[Version]): seq[PackageMinimalInfo] =
711695
let releases = getOfficialReleases(options)
@@ -857,11 +841,7 @@ proc getPackageMinimalVersionsFromRepo*(repoDir: string, pkg: PkgTuple, version:
857841
copyDir(repoDir, tempDir)
858842
tempDirCreated = true
859843
discard doCheckout(downloadMethod, tempDir, tag, versionDiscoveryOptions)
860-
let nimbleFile = findNimbleFile(tempDir, true, options, warn = false)
861-
if options.satResult.pass in {satNimSelection}:
862-
result.addUnique getPkgInfoFromDirWithDeclarativeParser(tempDir, options, nimBin).getMinimalInfo(options)
863-
else:
864-
result.addUnique getMinimalInfo(nimbleFile, options, nimBin)
844+
result.addUnique getPkgInfoFromDirWithDeclarativeParser(tempDir, options, nimBin).getMinimalInfo(options)
865845
#here we copy the directory to its own folder so we have it cached for future usage
866846
let downloadInfo = getPackageDownloadInfo((name, tagVersion.toVersionRange()), options)
867847
if not dirExists(downloadInfo.downloadDir):
@@ -874,18 +854,11 @@ proc getPackageMinimalVersionsFromRepo*(repoDir: string, pkg: PkgTuple, version:
874854

875855
# Add HEAD version last (tagged releases take precedence if same version exists)
876856
try:
877-
if options.satResult.pass in {satNimSelection}:
878-
result.addUnique getPkgInfoFromDirWithDeclarativeParser(repoDir, options, nimBin).getMinimalInfo(options)
879-
else:
880-
result.addUnique getPkgInfo(repoDir, options, nimBin).getMinimalInfo(options)
857+
result.addUnique getPkgInfoFromDirWithDeclarativeParser(repoDir, options, nimBin).getMinimalInfo(options)
881858
except CatchableError as e:
882859
displayWarning(&"Error getting package info for {name}: {e.msg}", HighPriority)
883860

884-
if not (options.satResult.pass == satNimSelection and options.satResult.declarativeParseFailed):
885-
#Dont save tagged versions if the declarative parser failed as this could cache the incorrect versions.
886-
#its suboptimal in the sense that next packages after failure wont be saved in the first past but there is a guarantee that there is a second pass in the case
887-
#the declarative parser fails so they will be saved then.
888-
saveTaggedVersions(name, result, options)
861+
saveTaggedVersions(name, result, options)
889862

890863
# Clean up tempDir if it was created
891864
if tempDirCreated:
@@ -954,11 +927,7 @@ proc getPackageMinimalVersionsFromRepoAsync*(repoDir: string, pkg: PkgTuple, ver
954927
# Fall back to checkout + VM parser if declarative parsing failed
955928
if not parsed:
956929
discard await doCheckoutAsync(downloadMethod, tempDir, tag, versionDiscoveryOptions)
957-
let nimbleFile = findNimbleFile(tempDir, true, options, warn = false)
958-
if options.satResult.pass in {satNimSelection}:
959-
result.addUnique getPkgInfoFromDirWithDeclarativeParser(tempDir, options, nimBin).getMinimalInfo(options)
960-
else:
961-
result.addUnique getMinimalInfo(nimbleFile, options, nimBin)
930+
result.addUnique getPkgInfoFromDirWithDeclarativeParser(tempDir, options, nimBin).getMinimalInfo(options)
962931
#here we copy the directory to its own folder so we have it cached for future usage
963932
let downloadInfo = getPackageDownloadInfo((name, tagVersion.toVersionRange()), options)
964933
if not dirExists(downloadInfo.downloadDir):
@@ -971,21 +940,14 @@ proc getPackageMinimalVersionsFromRepoAsync*(repoDir: string, pkg: PkgTuple, ver
971940

972941
# Add HEAD version last (tagged releases take precedence if same version exists)
973942
try:
974-
if options.satResult.pass in {satNimSelection}:
975-
result.addUnique getPkgInfoFromDirWithDeclarativeParser(repoDir, options, nimBin).getMinimalInfo(options)
976-
else:
977-
result.addUnique getPkgInfo(repoDir, options, nimBin).getMinimalInfo(options)
943+
result.addUnique getPkgInfoFromDirWithDeclarativeParser(repoDir, options, nimBin).getMinimalInfo(options)
978944
except CatchableError as e:
979945
displayWarning(&"Error getting package info for {name}: {e.msg}", HighPriority)
980946

981-
if not (options.satResult.pass == satNimSelection and options.satResult.declarativeParseFailed):
982-
#Dont save tagged versions if the declarative parser failed as this could cache the incorrect versions.
983-
#its suboptimal in the sense that next packages after failure wont be saved in the first past but there is a guarantee that there is a second pass in the case
984-
#the declarative parser fails so they will be saved then.
985-
try:
986-
saveTaggedVersions(name, result, options)
987-
except CatchableError as e:
988-
displayWarning(&"Error saving tagged versions for {name}: {e.msg}", LowPriority)
947+
try:
948+
saveTaggedVersions(name, result, options)
949+
except CatchableError as e:
950+
displayWarning(&"Error saving tagged versions for {name}: {e.msg}", LowPriority)
989951
finally:
990952
try:
991953
removeDir(tempDir)
@@ -1162,10 +1124,7 @@ proc downloadPkgFromUrlAsync*(pv: PkgTuple, options: Options, doPrompt = false,
11621124
proc downloadPkInfoForPvAsync*(pv: PkgTuple, options: Options, doPrompt = false, nimBin: string): Future[PackageInfo] {.async.} =
11631125
## Async version of downloadPkInfoForPv that downloads and gets package info.
11641126
let downloadRes = await downloadPkgFromUrlAsync(pv, options, doPrompt, nimBin)
1165-
if options.satResult.pass in {satNimSelection}:
1166-
return getPkgInfoFromDirWithDeclarativeParser(downloadRes[0].dir, options, nimBin)
1167-
else:
1168-
return getPkgInfo(downloadRes[0].dir, options, nimBin, forValidation = false, onlyMinimalInfo = false)
1127+
return getPkgInfoFromDirWithDeclarativeParser(downloadRes[0].dir, options, nimBin)
11691128

11701129
var downloadCache {.threadvar.}: Table[string, Future[seq[PackageMinimalInfo]]]
11711130

src/nimblepkg/packageinfotypes.nim

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -110,8 +110,8 @@ type
110110

111111
SATPass* = enum
112112
satNone
113-
satLockFile #From a lock file. SAT is not ran.
114-
satNimSelection #Declarative parser preferred. Fallback to VM parser if needed via bootstrapped nim
113+
satLockFile # From a lock file. SAT is not run.
114+
satSolving # SAT solver active, declarative parser with atomic VM fallback
115115
satDone
116116

117117
NimResolved* = object
@@ -143,7 +143,6 @@ type
143143
pass*: SATPass
144144
installedPkgs*: seq[PackageInfo] #Packages installed in the current pass
145145
buildPkgs*: seq[PackageInfo] #Packages that were built in the current pass
146-
declarativeParseFailed*: bool
147146
nimResolved*: NimResolved
148147
bootstrapNim*: BootstrapNim #The nim that we are going to use if we dont have a nim resolved yet and the declarative parser failed. Notice this is required to Atomic Parser fallback (not implemented)
149148
normalizedRequirements*: Table[string, string] #normalized -> old. Some packages are not published as nimble packages, we keep the url for installation.
@@ -178,7 +177,7 @@ proc getGloballyActiveFeatures*(): seq[string] =
178177

179178
proc initSATResult*(pass: SATPass): SATResult =
180179
SATResult(pkgsToInstall: @[], solvedPkgs: @[], output: "", pkgs: initHashSet[PackageInfo](),
181-
pass: pass, installedPkgs: @[], declarativeParseFailed: false,
180+
pass: pass, installedPkgs: @[],
182181
normalizedRequirements: initTable[string, string](),
183182
gitErrors: @[],
184183
lockFileVcsRevisions: initTable[string, Sha1Hash]()

src/nimblepkg/vnext.nim

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@ proc debugSATResult*(options: Options, calledFrom: string) =
3838
else:
3939
echo "No Nim selected"
4040
echo color, "Bootstrap Nim: ", reset, "isSet: ", satResult.bootstrapNim.nimResolved.pkg.isSome, " version: ", satResult.bootstrapNim.nimResolved.version
41-
echo color, "Declarative parser failed: ", reset, satResult.declarativeParseFailed
41+
4242
let pkgsWithErrors = satResult.pkgs.toSeq.filterIt(it.declarativeParserErrors.len > 0)
4343
if pkgsWithErrors.len > 0:
4444
echo color, "Declarative parser errors: ", reset
@@ -639,9 +639,6 @@ proc resolveAndConfigureNim*(rootPackage: PackageInfo, pkgList: seq[PackageInfo]
639639
# setBootstrapNim(systemNimPkg, pkgListDecl, options)
640640
#TODO NEXT PR
641641
#At this point, if we failed before to parse the pkglist. We need to reparse with the bootsrapped nim as we may have missed some deps.
642-
# if options.satResult.declarativeParseFailed:
643-
# echo "FAILED TO PARSE THE PKGLIST, REPARSING WITH BOOTSTRAPPED NIM"
644-
# debugSatResult(options, "resolveAndConfigureNim")
645642

646643

647644
var resolvedNim = resolveNim(rootPackage, pkgListDecl, systemNimPkg, options)

0 commit comments

Comments
 (0)