-
-
Notifications
You must be signed in to change notification settings - Fork 1.5k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
make distinct conversions addressable in VM (#24124)
fixes #24097 For `nkConv` addresses where the conversion is between 2 types that are equal between backends, treat assignments the same as assignments to the argument of the conversion. In the VM this seems to be in `genAsgn` and `genAsgnPatch`, as evidenced by the special logic for `nkDerefExpr` etc. This doesn't handle ranges after #24037 because `sameBackendType` is used and not `sameBackendTypeIgnoreRange`. This is so this is backportable without #24037 and another PR can be opened that implements it for ranges and adds tests as well. We can also merge `sameBackendTypeIgnoreRange` with `sameBackendType` since it doesn't seem like anything that uses it would be affected (only cycle checks and the VM), but then we still have to add tests.
- Loading branch information
Showing
2 changed files
with
65 additions
and
10 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,49 @@ | ||
block: # issue #24097 | ||
type Foo = distinct int | ||
proc foo(x: var Foo) = | ||
int(x) += 1 | ||
proc bar(x: var int) = | ||
x += 1 | ||
static: | ||
var x = Foo(1) | ||
int(x) = int(x) + 1 | ||
doAssert x.int == 2 | ||
int(x) += 1 | ||
doAssert x.int == 3 | ||
foo(x) | ||
doAssert x.int == 4 | ||
bar(int(x)) # need vmgen flags propagated for this | ||
doAssert x.int == 5 | ||
type Bar = object | ||
x: Foo | ||
static: | ||
var obj = Bar(x: Foo(1)) | ||
int(obj.x) = int(obj.x) + 1 | ||
doAssert obj.x.int == 2 | ||
int(obj.x) += 1 | ||
doAssert obj.x.int == 3 | ||
foo(obj.x) | ||
doAssert obj.x.int == 4 | ||
bar(int(obj.x)) # need vmgen flags propagated for this | ||
doAssert obj.x.int == 5 | ||
static: | ||
var arr = @[Foo(1)] | ||
int(arr[0]) = int(arr[0]) + 1 | ||
doAssert arr[0].int == 2 | ||
int(arr[0]) += 1 | ||
doAssert arr[0].int == 3 | ||
foo(arr[0]) | ||
doAssert arr[0].int == 4 | ||
bar(int(arr[0])) # need vmgen flags propagated for this | ||
doAssert arr[0].int == 5 | ||
proc testResult(): Foo = | ||
result = Foo(1) | ||
int(result) = int(result) + 1 | ||
doAssert result.int == 2 | ||
int(result) += 1 | ||
doAssert result.int == 3 | ||
foo(result) | ||
doAssert result.int == 4 | ||
bar(int(result)) # need vmgen flags propagated for this | ||
doAssert result.int == 5 | ||
doAssert testResult().int == 5 |