-
-
Notifications
You must be signed in to change notification settings - Fork 1.5k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
fix #14339, #13511, #14420: fixes limited VM support for addr #16002
Merged
Merged
Changes from all commits
Commits
Show all changes
5 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
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 |
---|---|---|
@@ -1,61 +1,69 @@ | ||
import sequtils, critbits | ||
import std/[sequtils,critbits] | ||
|
||
template main = | ||
var r: CritBitTree[void] | ||
r.incl "abc" | ||
r.incl "xyz" | ||
r.incl "def" | ||
r.incl "definition" | ||
r.incl "prefix" | ||
r.incl "foo" | ||
|
||
var r: CritBitTree[void] | ||
r.incl "abc" | ||
r.incl "xyz" | ||
r.incl "def" | ||
r.incl "definition" | ||
r.incl "prefix" | ||
r.incl "foo" | ||
doAssert r.contains"def" | ||
|
||
doAssert r.contains"def" | ||
r.excl "def" | ||
assert r.missingOrExcl("foo") == false | ||
assert "foo" notin toSeq(r.items) | ||
|
||
r.excl "def" | ||
assert r.missingOrExcl("foo") == false | ||
assert "foo" notin toSeq(r.items) | ||
assert r.missingOrExcl("foo") == true | ||
|
||
assert r.missingOrExcl("foo") == true | ||
assert toSeq(r.items) == @["abc", "definition", "prefix", "xyz"] | ||
|
||
assert toSeq(r.items) == @["abc", "definition", "prefix", "xyz"] | ||
assert toSeq(r.itemsWithPrefix("de")) == @["definition"] | ||
var c = CritBitTree[int]() | ||
|
||
assert toSeq(r.itemsWithPrefix("de")) == @["definition"] | ||
var c = CritBitTree[int]() | ||
c.inc("a") | ||
assert c["a"] == 1 | ||
|
||
c.inc("a") | ||
assert c["a"] == 1 | ||
c.inc("a", 4) | ||
assert c["a"] == 5 | ||
|
||
c.inc("a", 4) | ||
assert c["a"] == 5 | ||
c.inc("a", -5) | ||
assert c["a"] == 0 | ||
|
||
c.inc("a", -5) | ||
assert c["a"] == 0 | ||
c.inc("b", 2) | ||
assert c["b"] == 2 | ||
|
||
c.inc("b", 2) | ||
assert c["b"] == 2 | ||
c.inc("c", 3) | ||
assert c["c"] == 3 | ||
|
||
c.inc("c", 3) | ||
assert c["c"] == 3 | ||
c.inc("a", 1) | ||
assert c["a"] == 1 | ||
|
||
c.inc("a", 1) | ||
assert c["a"] == 1 | ||
var cf = CritBitTree[float]() | ||
|
||
var cf = CritBitTree[float]() | ||
cf.incl("a", 1.0) | ||
assert cf["a"] == 1.0 | ||
|
||
cf.incl("a", 1.0) | ||
assert cf["a"] == 1.0 | ||
cf.incl("b", 2.0) | ||
assert cf["b"] == 2.0 | ||
|
||
cf.incl("b", 2.0) | ||
assert cf["b"] == 2.0 | ||
cf.incl("c", 3.0) | ||
assert cf["c"] == 3.0 | ||
|
||
cf.incl("c", 3.0) | ||
assert cf["c"] == 3.0 | ||
assert cf.len == 3 | ||
cf.excl("c") | ||
assert cf.len == 2 | ||
|
||
assert cf.len == 3 | ||
cf.excl("c") | ||
assert cf.len == 2 | ||
var cb: CritBitTree[string] | ||
cb.incl("help", "help") | ||
for k in cb.keysWithPrefix("helpp"): | ||
doAssert false, "there is no prefix helpp" | ||
|
||
var cb: CritBitTree[string] | ||
cb.incl("help", "help") | ||
for k in cb.keysWithPrefix("helpp"): | ||
doAssert false, "there is no prefix helpp" | ||
block: # bug #14339 | ||
var strings: CritBitTree[int] | ||
discard strings.containsOrIncl("foo", 3) | ||
doAssert strings["foo"] == 3 | ||
|
||
main() | ||
static: main() |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Doesn't that mean that when you do
somePtr = addr someOtherPtr
it will behave likesomePtr = someOtherPtr
?There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I don't believe so; eg:
=> CT behaves like RT
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Hmm, I'm struggling to come up with a concrete example, but please explain why it is correct (?) and maybe add a comment.
Your example isn't exactly convincing because
f4
isptr ptr Foo
and it gets automatically dereferenced. If you changeFoo
to be a non-ref object it fails.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
just filed #16020, but this is a pre-existing bug and this PR exercises a different code path, see https://gist.github.com/timotheecour/fc575c054cddba5bea32df98d1c50cdc
TODO on me
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@Clyybber my understanding is there's an implicit deref that occurs in code paths that lead here due to semantic transform that generates a temporary for block return expressions (without
result = expr
or return expr`)eg:
which is transformed into:
instead of:
this seems related to #16137
This PR is still good IMO (more things now work, and hopefully nothing breaks), but I agree that the code transformation needs to be revisited as @cooldome mentioned here: #14420 (comment)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The code transformation is correct and is not what my question is about.
I'm asking how treating
... = addr someAddress
as if it were... = someAddress
is correct/sound here.