forked from nim-lang/nimble
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
WIP SAT solver integration fixes nim-lang#1162
- Loading branch information
Showing
16 changed files
with
34,006 additions
and
4 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,54 @@ | ||
import std/tables | ||
import sat, satvars #Notice this two files eventually will be a package. They are copied (untouch) from atlas | ||
import version, packageinfotypes | ||
|
||
type | ||
SatVarInfo* = object # attached information for a SAT variable | ||
pkg: string | ||
version: Version | ||
index: int | ||
|
||
Form* = object | ||
f*: Formular | ||
mapping: Table[VarId, SatVarInfo] | ||
idgen: int32 | ||
|
||
proc toFormular*(requirements: seq[PkgTuple], allPackages: seq[PackageBasicInfo]): Form = | ||
var b = Builder() | ||
var idgen: int32 = 0 | ||
var mapping = initTable[VarId, SatVarInfo]() | ||
b.openOpr(AndForm) | ||
|
||
for (pkgName, constraint) in requirements: | ||
b.openOpr(ExactlyOneOfForm) | ||
for pkg in allPackages: | ||
if pkg.name != pkgName: continue | ||
if pkg.version.withinRange(constraint): | ||
let vid = VarId(idgen) | ||
b.add(newVar(vid)) | ||
mapping[vid] = SatVarInfo(pkg: pkgName, version: pkg.version, index: idgen) | ||
inc idgen | ||
b.closeOpr() | ||
|
||
b.closeOpr() | ||
Form(f: b.toForm(), mapping: mapping, idgen: idgen) | ||
|
||
proc getPackageVersions*(form: Form, s: var Solution): Table[string, Version] = | ||
let m = maxVariable(form.f) | ||
result = initTable[string, Version]() | ||
for i in 0..<m: | ||
let varId = VarId(i) | ||
if isTrue(s, varId): | ||
if varId in form.mapping: | ||
let info = form.mapping[varId] | ||
result[info.pkg] = info.version | ||
|
||
proc areRequirementsWithinPackages*(requirements: seq[PkgTuple], allPackages: seq[PackageBasicInfo]): bool = | ||
var found = 0 | ||
for (pkgName, constraint) in requirements: | ||
for pgk in allPackages: | ||
if pkgName == pgk.name and pgk.version.withinRange(constraint): | ||
inc found | ||
break | ||
found == requirements.len | ||
|
Oops, something went wrong.